DavG63
02-02-2016, 01:52 AM
Hi all
I have the following code which works for me in removing blank rows from a table on the Y-axis of the row is blank.
On another document I have, there are four table cells, spaced horizontally on the same row. What I'm looking to do is adapt the below check for an individual cell within that row as being blank, and if it finds one, to delete that cell and to shift any of the cells to the right of it which do have a value, to the left - in other words, potentially delete one of the middle boxes and then have it all automatically bunch back up.
Application.ScreenUpdating = FalseDim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
With ActiveDocument.Sections(2).Range
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True
Is there any easy way to do this that anyone is aware of?
Thanks
Dav
I have the following code which works for me in removing blank rows from a table on the Y-axis of the row is blank.
On another document I have, there are four table cells, spaced horizontally on the same row. What I'm looking to do is adapt the below check for an individual cell within that row as being blank, and if it finds one, to delete that cell and to shift any of the cells to the right of it which do have a value, to the left - in other words, potentially delete one of the middle boxes and then have it all automatically bunch back up.
Application.ScreenUpdating = FalseDim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
With ActiveDocument.Sections(2).Range
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True
Is there any easy way to do this that anyone is aware of?
Thanks
Dav