Good evening! I have a 200+ page document with a table on each page and blank rows in each table (following a dodgy Excel mailmerge). Is there a non-manual way of removing the rows from the tables en masse please? :confused:
Thanks for reading !
Printable View
Good evening! I have a 200+ page document with a table on each page and blank rows in each table (following a dodgy Excel mailmerge). Is there a non-manual way of removing the rows from the tables en masse please? :confused:
Thanks for reading !
I have some macros I wrote to do various jobs on rows of tables. I'm sure they could be altered for you requirements. I will have a look tomorrow if nobody else posts anything.
Sorry I forgot about this try something like
That should go through every table and if 2 cells are empty it will delete the row. You can adjust the if statement to suit your needs.Code:Sub CleanUpTables()
Dim oTbl As Table
Dim r As Row
Dim RowContents As String
For Each oTbl In ActiveDocument.Tables
For Each oRow In oTbl.Rows
If CellText(oRow.Cells(1).Range.Text) = "" And CellText(oRow.Cells(2).Range.Text) = "" Then
oRow.Delete
End If
Next
Next
End Sub
You need to loose the last and first line if you are making a new macro and putting it in.
Sorry I just noticed the procedure you were on about, I will dig it out tomorrow.
Here is the missing code.This is it in full now.Code:Function CellText(strIn As String) As String
CellText = Left(strIn, Len(strIn) - 2)
End Function
Sub CleanUpTables()
Dim oTbl As Table
Dim r As Row
Dim RowContents As String
For Each oTbl In ActiveDocument.Tables
For Each oRow In oTbl.Rows
If CellText(oRow.Cells(1).Range.Text) = "" And CellText(oRow.Cells(2).Range.Text) = "" Then
oRow.Delete
End If
Next
Next
End Sub