Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Counting non-blank cells in a column

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word tables
View previous topic :: View next topic  
Author Message
Ron
Guest





PostPosted: Tue Dec 18, 2007 8:51 pm    Post subject: Counting non-blank cells in a column Reply with quote

Does anyone have a formula for counting the number of cells in a column that
contain text?

We are trying to count the number of names that appear in a column.
Back to top
Google
Sponsor





PostPosted: Tue Dec 18, 2007 8:51 pm    Post subject: Advertisement

Back to top
Lene Fredborg
Guest





PostPosted: Tue Dec 18, 2007 11:41 pm    Post subject: RE: Counting non-blank cells in a column Reply with quote

You can use a macro. The following macro will count all non-blank cells in
the (first) column in the selection. A message displays the result.

You do not need to select the entire column before running the macro. It
will check all cells even if you have only an insertion point or if part of
the column selected.

Note that the macro will consider a cell as non-blank even if the cell
contains spaces only. Additional code can be added to prevent this if desired.

Sub CountNonBlankCellsInColumn()

Dim oCell As Cell
Dim n As Long 'used as counter

n = 0
'Check whether selection is in table
If Selection.Information(wdWithInTable) = False Then
MsgBox "The selection must be in a table. Please retry.", vbOKOnly
Exit Sub
End If
‘Check all cells in the first column in the selection
For Each oCell In Selection.Columns(1).Cells
'Check whether row is empty - delete if it is
If Len(oCell.Range.Text) > 2 Then
'Cell is not empty - count
n = n + 1
End If
Next oCell

'Show message
MsgBox "The (first) column in the selection contains " & n & _
" non-blank cells."
End Sub

For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ron" wrote:

Quote:
Does anyone have a formula for counting the number of cells in a column that
contain text?

We are trying to count the number of names that appear in a column.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word tables All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum