View Single Post
 
Old 01-05-2022, 05:24 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If all the cells in the relevant columns are empty or contain 0 the following will delete the row:
Code:
Sub DeleteBlankRowsAndTablesInATable()
Dim objCell As Range
Dim nRowIndex As Integer, nRows As Integer, nColumns As Integer, nColumnIndex As Integer
Dim varCellEmpty As Boolean

    Application.ScreenUpdating = False

    If Selection.Information(wdWithInTable) = False Then
        MsgBox ("Put cursor inside a table first!")
        Exit Sub
    Else
        With Selection.Tables(1)
            nRows = .Rows.Count
            For nRowIndex = nRows To 1 Step -1
                varCellEmpty = True
                For nColumns = 5 To .Columns.Count
                    Set objCell = .Rows(nRowIndex).Cells(nColumns).Range
                    objCell.End = objCell.End - 1
                    If Len(objCell) > 0 And Not objCell.Text = "0" Then
                        varCellEmpty = False
                        Exit For
                    End If
                Next nColumns
                If varCellEmpty = True Then .Rows(nRowIndex).Delete
            Next nRowIndex
        End With
    End If
    Set objCell = Nothing
    Application.ScreenUpdating = True
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote