G
Greg Maxey
An OP asked how to count and display the number of cells "in use" in a table
column. I monkeyed around with a macro which works "part time." I put the
cursor in the table cell and run the macro and it reports the number of
cells used in that row. My problem is that it only works for the first
table in the document. If I add a table and run the macro, the result is
put in the first table. Here is what I have with comments:
Sub Test()
Dim i As Long, j As Long, k As Long ' k is supposed to be the Table index
:-(
Dim iCount As Long
Dim oCell As Cell
Dim oCol As Column
If Selection.Information(wdWithInTable) = True Then
'k = Selection.Cells(1).Tables 'I can't figure out how to determine the
table index
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(k).Cell(i, j).Range.InsertBefore "Count = " & iCount &
" "
'the above line works when .Tables(k) is .Table(1) but the result is alwasy
in Table 1. I want the result in the Table that has focus.
'The following line is what I think should work if I could determine k.
ActiveDocument.Tables(k).Cell(i, j).Range.InsertBefore "Count = " & iCount &
" "
End Sub
column. I monkeyed around with a macro which works "part time." I put the
cursor in the table cell and run the macro and it reports the number of
cells used in that row. My problem is that it only works for the first
table in the document. If I add a table and run the macro, the result is
put in the first table. Here is what I have with comments:
Sub Test()
Dim i As Long, j As Long, k As Long ' k is supposed to be the Table index
:-(
Dim iCount As Long
Dim oCell As Cell
Dim oCol As Column
If Selection.Information(wdWithInTable) = True Then
'k = Selection.Cells(1).Tables 'I can't figure out how to determine the
table index
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(k).Cell(i, j).Range.InsertBefore "Count = " & iCount &
" "
'the above line works when .Tables(k) is .Table(1) but the result is alwasy
in Table 1. I want the result in the Table that has focus.
'The following line is what I think should work if I could determine k.
ActiveDocument.Tables(k).Cell(i, j).Range.InsertBefore "Count = " & iCount &
" "
End Sub