VBA Delete row if certain cell ifs blank

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
149
Hey, everyone,
I need your help once again.

I have lots of data and would need to delete rows if certain cells are blank (For instance, if column X, Z or Y in a row are blank, I want the macro to delete the whole row)

Typically I would try to do it myself but I have a deadline and time is running out. Do you think you could help me out?

Kind regards,
 
Assuming you have values in all rows in column "A"
Try this:
Code:
Sub Filter_Me()
'Modified 3-4-2018 10:25 AM EST
   Application.ScreenUpdating = False
     Dim i As Long
    
    For i = 1 To 3
    With ActiveSheet.Range("X1:Z" & Cells(Rows.Count, "A").End(xlUp).Row)
        .AutoFilter i, Criteria1:=""
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
       End With
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Another option is
Code:
Sub delrws()
   Dim i As Long
   For i = 24 To 26
      Columns(i).SpecialCells(xlBlanks).EntireRow.Delete
   Next i
End Sub
 
Last edited:
Upvote 0
Peter:
I hear people on this forum saying don't use loops they are too slow.
So I use filter but your saying your script which uses a loop is faster then a filter. Why is that?
I answered that exact question for you a few months ago. :)
Refer to the first part of this post.


@ ORoxo
For consideration if your data is large. Testing the codes suggested on 10,000 rows of data, about 3,000 of which require deletion:

Post # 2: 11.938 seconds
Post # 4: 7.109 secs
Post # 5: 0.078 secs
Post # 6: 6.719 secs
Post # 7: 4.641 secs
Updating for the new suggestions (same sample data)
Post #11 : 2.480 secs
Post #12 : 2.301 secs
 
Upvote 0
Thanks, guys!!

I tried all the solutions provided and all of them worked like a charm!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Oroxo,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top