Hi
I've wriiten a small word macro to loop through a series of tables and delete any blank cells, Now it works fine for the 1st table and correctly selects the second table but then deletes a cell from the 1st table, and now I'm a tad lost as to why this is, I wrongly assumed changing the 1 to 2 /3/4 in Selection.Tables(1) would tell the macro which table to use. If I comment out the delete cells the macro will correctly loop through any amount of tables. (msgbox is purely ro help me during run through).
Word Macro
The word document has a number of 11 single column tables with currently 7 rows with the top cell being the header, once empty cells are deleted I want to format the text.
Table1
Table 2
Table 3
Table 4
Table 5
Table 6
Table 7
Table 8 to 11 similar with up to 7 entries
I've wriiten a small word macro to loop through a series of tables and delete any blank cells, Now it works fine for the 1st table and correctly selects the second table but then deletes a cell from the 1st table, and now I'm a tad lost as to why this is, I wrongly assumed changing the 1 to 2 /3/4 in Selection.Tables(1) would tell the macro which table to use. If I comment out the delete cells the macro will correctly loop through any amount of tables. (msgbox is purely ro help me during run through).
Word Macro
Code:
Sub FindTables()
Dim iResponse As Integer
Dim tTable As Table
Dim oCell As Cell
Dim oRow As Row
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
tTable.Select
For Each oRow In Selection.Tables(1).Rows
For Each oCell In oRow.Cells
If oCell.Range.Text = Chr(13) & Chr(7) Then
MsgBox oCell.RowIndex & " " & oCell.ColumnIndex & " is empty."
ActiveDocument.Tables(1).Cell(oCell.RowIndex, oCell.ColumnIndex).Delete
End If
Next oCell
Next oRow
Next
MsgBox prompt:="Search Complete.", Buttons:=vbInformation
End Sub
Table1
DETECTORS |
SMOKE |
Table 2
WALKWAYS |
CLEAR |
Table 3
SIGNAGE |
INPLACE |
Table 4
OXYGEN |
AMBIENT |
Table 5
FIRE DOORS |
NO |
Table 6
SOURCES OF IGNITION |
CANDLES |
FLY KILLER |
KETTLE |
WASHING MACHINE |
Table 7
FIRE BLANKET |
NONE |
Table 8 to 11 similar with up to 7 entries
Last edited by a moderator: