View Single Post
 
Old 08-07-2014, 06:52 AM
Faugs Faugs is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Aug 2014
Posts: 5
Faugs is on a distinguished road
Default

Thank you for the assistance, Macropod! You have led me in the right direction, however I am not there just yet.

I have found a similar macro that will remove a table's column ONLY if the entire column is completely blank (see below).

Code:
Sub DeleteEmptyTablerowsandcolumns()
Application.ScreenUpdating = False
Dim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Columns.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Columns(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Columns(i).Delete
Next i
Next Tbl
End With
With ActiveDocument
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
End Sub
The results of this code are as follows:

The second column is completely blank, so the macro deletes the entire column.




HOWEVER, I would like to tweak the VBA code above to check if ANY cells are blank within the table. If there is even 1 blank cell, delete the ENTIRE column.

See desired results below (you can see Column 2, cell D is blank, so the entire column should be deleted):



If you could help me tweak the VBA code above to complete this task, I would be very appreciative!!!
Attached Images
File Type: jpg Current_Macro.jpg (111.3 KB, 31 views)
File Type: jpg Needed_Macro.jpg (114.6 KB, 31 views)
Reply With Quote