View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Count of a unique letter in a column

The following macro will total the Ys and Ns for each table and add them
with the total for the document at the end of the document.

Dim oTable As Table
Dim lYesDOC As Long
Dim lNoDOC As Long
Dim lYesTAB As Long
Dim lNoTAB As Long
Dim LastCell As Range
lYesDOC = 0
lNoDOC = 0
For i = 1 To ActiveDocument.Tables.Count
lYesTAB = 0
lNoTAB = 0
Set oTable = ActiveDocument.Tables(i)
For j = 1 To oTable.Rows.Count
If InStr(1, UCase(oTable.Cell(j, 3).Range), "Y") Then
lYesDOC = lYesDOC + 1
lYesTAB = lYesTAB + 1
End If
If InStr(1, UCase(oTable.Cell(j, 3).Range), "N") Then
lNoDOC = lNoDOC + 1
lNoTAB = lNoTAB + 1
End If
Next j
If i = 1 Then
ActiveDocument.Range.InsertAfter vbCr & _
"Sub totals:"
End If
ActiveDocument.Range.InsertAfter vbCr & _
"Table " & i & ": Yes - " & _
lYesTAB & " No - " & lNoTAB
Next i
ActiveDocument.Range.InsertAfter vbCr & _
"Totals: Yes - " & lYesDOC & " No - " & lNoDOC


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


DeanH wrote:
Word 2003 on XP.
I have a document that contains multiple tables, in each table the
thrid column contains "Y" or "N". I wish to count the occurances of
both of these characters, either 1) at the bottom of each table,
and/or 2) total number of both of these characters in all of the
tables in the document.
Any help will be greatly appreciated.
DeanH