View Single Post
  #4   Report Post  
Greg
 
Posts: n/a
Default

Brad,

OK this looks gnarly but seems to work. I inserted a half a dozen two
colunm tables. I headed three of the tables Short List and Long List.
I headed the other three Long List and Short List. I then filled all
of the long lists and "shorted" the short list. I then ran the
following macro which appears to put the percentage in the correct
column. As an added advantage, it doesn't matter if the long list is
full and it doesn't matter if the short list has empty cells between
addresses :-)

Sub ScratchMacro2()
Dim iCol1Count As Long
Dim iCol2Count As Long
Dim oCell As Cell
Dim oCol As Column
Dim oTable As Table
Dim i As Long
For i = 1 To ActiveDocument.Tables.Count
Set oTable = ActiveDocument.Tables(i)
Set oCol = oTable.Columns(1)
iCol1Count = -1
For Each oCell In oCol.Cells
If oCell.Range.Characters.Count 1 Then
iCol1Count = iCol1Count + 1
End If
Next
Set oCol = Nothing
Set oCol = oTable.Columns(2)
iCol2Count = -1
For Each oCell In oCol.Cells
If oCell.Range.Characters.Count 1 Then
iCol2Count = iCol2Count + 1
End If
Next
If iCol1Count iCol2Count Then
oTable.Cell(1, 1).Range.Select
Selection.InsertAfter " " & Round((iCol1Count / _
iCol2Count) * 100, 2) & " %"
Else
oTable.Cell(1, 2).Range.Select
Selection.InsertAfter " " & Round((iCol2Count / _
iCol1Count) * 100, 2) & " %"
End If
Next
End Sub