Jump to content

Recommended Posts

Posted

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 !

Posted
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.
  • Thanks 1
Posted

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.

  • Thanks 1
Posted
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.?

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...