Count non-blank cells in a table column

  • Thread starter Thread starter Bradley C. Hammerstrom
  • Start date Start date
B

Bradley C. Hammerstrom

The field code {=Count(Below)} works for me, but I want to skip blank cells
in the column. How?
 
Hi Bradley,

Word's 'Above', 'Below', 'Right' and 'Left' field expressions are quirky at
the best of times - see 'Referencing Adjacent Cells In A Row Or Column' in
the Word document at:
www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=365442
(url all one line)

Having said that, you can't reliably avoid counting empty/blank cells with
{=Count(Below)}. A possible workaround, if you're counting cells with '1' in
them (or another non-zero numeric constant), might be to use something based
on {=Sum(Below)}.

Cheers
 
Bradley,

I don't know how you could do this with a field. I played with a macro
today that if you put your cursor in the a blank cell in the column then it
will count a inert the number of "non-empty" fields.

Sub Test()
Dim i As Long, j As Long
Dim iCount As Long
Dim oCell As Cell
Dim oCol As Column

If Selection.Information(wdWithInTable) = True Then
i = Selection.Cells(1).RowIndex
j = Selection.Cells(1).ColumnIndex
End If
For Each oCell In Selection.Tables(1).Columns(j).Cells
If oCell.Range.Characters.Count > 1 Then
iCount = iCount + 1
End If
Next
ActiveDocument.Tables(1).Cell(i, j).Range.InsertBefore "Count = " & iCount &
" "


End Sub
 
I believe you will want to use the code "COUNTA". It is specifaclly designed
to counta only non-blank cells. Also, if you want to only count cells that
contain numbers, i.e. don't count a heading, use "DCOUNT". Hope htis helps.
 
Back
Top