Delete empty rows based on 2 cell values

Sub DeleteEmptyRows()
Dim iStartRow As Integer, iSections As Integer, iCounter As Integer
Dim bEndMe As Boolean, bOneRemoved As Boolean
Dim sRange As String
Dim sRange2 As String

    bEndMe = False
iStartRow = 2

   Do
        ‘Look in 2 cells to determine if the row is blank
        sRange = “N” & CStr(iStartRow)
        sRange2 = “O” & CStr(iStartRow)
        bOneRemoved = False
        
        If Range(sRange).Value = “” And Range(sRange2).Value = “” Then
            sRange = CStr(iStartRow) & “:” & CStr(iStartRow)
            Rows(sRange).Select
            Selection.Delete Shift:=xlUp
            bOneRemoved = True
        End If
        sRange = “A” & CStr(iStartRow)
        If Range(sRange).Value = “” Then bEndMe = True
        
        If bOneRemoved = False Then
            iStartRow = iStartRow + 1
        Else
            ‘The row was deleted so do not increment
            iStartRow = iStartRow
        End If
    Loop Until bEndMe = True
End Sub

Leave a Reply