View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey
 
Posts: n/a
Default Count table rows with specific value in a column

I am assuming that you mean a single "A" or a single "M" in the cell.

Try:
Sub RowCnt()
Dim oTbl As Word.Table
Dim oRows As Rows
Dim pColCnt As Long
Dim i As Long
Dim j As Long
Dim oCell As Word.Range
Dim oCnt As Long
Set oTbl = Selection.Tables(1)
Set oRows = oTbl.Rows
For i = 2 To oRows.Count
pColCnt = oTbl.Rows(i).Cells.Count
For j = 1 To pColCnt
Set oCell = oTbl.Cell(i, j).Range
oCell.MoveEnd wdCharacter, -1
Select Case oCell.Text
Case "M"
oCnt = oCnt + 1
Exit For
Case "A"
oCnt = oCnt + 1
Exit For
Case Else
'Do Nothing
End Select
Next j
Next i
MsgBox oCnt
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


kaz wrote:
Hi there

I have a table where I am counting the number of rows, excluding the
header row, with the result of the count being displayed in another
part of the Word document. That works very well using a macro (after I
sought advice here a while back).

Now I am told I need to have two counts displaying information from
this table. The first is the one I have already got. The second is a
count of rows in the table, excluding the header row, where one of the
columns has a value of A or M. Any clues on how I can achieve that?

Carolyn