View Single Post
 
Old 10-20-2016, 01:25 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub DeleteEmptyTableRowsAndColumns()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
For Each Tbl In ActiveDocument.Tables
  With Tbl
    For i = .Rows.Count To 1 Step -1
      With .Rows(i)
        If Len(.Range) = .Cells.Count * 2 + 2 Then .Delete
      End With
    Next i
    With .Range
      For i = .Cells.Count To 1 Step -1
        On Error Resume Next
        If Len(.Cells(i).Range) = 2 Then
          .Columns(.Cells(i).ColumnIndex).Delete
        End If
      Next i
    End With
  End With
Next Tbl
Set Tbl = Nothing
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags, inserted via the # button on the posting menu.

PPS: Note also how much simpler and more efficient the row deletion code can be.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote