Posted: Tue Dec 18, 2007 11:41 pm Post subject: RE: Counting non-blank cells in a column
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
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