Reputation: 35
Can someone please tell me why, when I run this code, it skips the tbl.Range.Rows(i).Delete line when there are rows in my table which are empty?
Many thanks
Debbie
Dim i As Long Dim tbl As Table
Set tbl = ActiveDocument.Tables(2)
For i = tbl.Range.Rows.Count To 1 Step -1
With tbl
If IsEmpty(tbl.Range.Rows(i)) = True Then
tbl.Range.Rows(i).Delete
End If
End With
Next
Upvotes: 0
Views: 53
Reputation: 13490
The simple answer is that, in Word, a row is never empty - it always contains end-of-cell and end-of-row characters. Try:
Dim r As Long
With ActiveDocument.Tables(2)
For r = .Rows.Count To 1 Step -1
With .Rows(r)
If Len(.Range.Text) = .Cells.Count * 2 + 2 Then .Delete
End With
Next r
End With
Note that the above code won't work if the table has vertically-merged/split cells.
Upvotes: 1