• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to Delete Entire Row if Cells are empty/blank

Hello once again,

I thought this macro was working yesterday, but today it's not (perhaps I was just dreaming!!)

What it is supposed to do is go through each line and if cells A:I are empty/blank delete the entire row. When I hover over the code it always states: True=True which really should be deleting all the rows, but none are being deleting.

Any help is appreciated.
Code:
For lngI = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count To 1 Step -1
    With Cells(lngI, "A")
        If IsEmpty(Range("A" & lngI & ":" & "I" & lngI)) = True Then .EntireRow.Delete
    End With
Next
 
IsEmpty can only be used for single cell/reference. Try below instead.

Code:
For lngI = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count To 1 Step -1
    With Cells(lngI, "A")
        If Application.WorksheetFunction.CountA(Range("A" & lngI & ":" & "I" & lngI)) = 0 Then .EntireRow.Delete
    End With
Next

FYI - IsEmpty in your code should always return False. Try adding Debug.Print IsEmpty(Range("A" & lngI & ":" & "I" & lngI)) line below With line of your code.
 
Back
Top