CarpeDiem Posted March 2, 2012 Posted March 2, 2012 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? Thanks for reading !
ChrisH Posted March 2, 2012 Posted March 2, 2012 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. 1
ChrisH Posted March 5, 2012 Posted March 5, 2012 Sorry I forgot about this try something like 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 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. 1
CarpeDiem Posted March 5, 2012 Author Posted March 5, 2012 Sorry I forgot about this try something like 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 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. Hi Chris Super - thanks. I've added this to a new macro and V-B says Compile error : Sub or Function not defined.?
ChrisH Posted March 5, 2012 Posted March 5, 2012 You need to loose the last and first line if you are making a new macro and putting it in.
ChrisH Posted March 5, 2012 Posted March 5, 2012 Sorry I just noticed the procedure you were on about, I will dig it out tomorrow.
ChrisH Posted March 6, 2012 Posted March 6, 2012 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 Here is the missing code.This is it in full now.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now