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

OK, try:
Sub RowCnt()
Dim oTbl As Word.Table
Dim oRows As Rows
Dim pColCnt As Long
Dim i 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
If oTbl.Rows(i).Cells.Count = 6 Then
Set oCell = oTbl.Cell(i, 6).Range
oCell.MoveEnd wdCharacter, -1
Select Case oCell.Text
Case "M"
oCnt = oCnt + 1
Case "A"
oCnt = oCnt + 1
Case Else
'Do Nothing
End Select
End If
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 Greg
Yes it is for a single M or A. That macro is great! Of course I always
forget to mention at least one thing......

There are two potential columns which can contain these values but I
only want to include the rows where the value is in a specific column
- the 6th column.

Carolyn