Macro to delete a whole row based on a blank cell

Ashe77

New Member
Joined
May 23, 2013
Messages
13
Hi

I'm trying to create a macro whereby a whole row can be deleted if there are blank cells in column B

I have the below which works perfect in terms of deleting the rows BUT keeps on running after completing, endlessly going. I have to ESC to stop it. What's wrong?

Thanks in advance




Code:
Sub DeleteRow()
Dim rngFind As Range


Do
Set rngFind = Activesheet.Range("B1:B200").Find(What:="", LookAt:=xlWhole)
If Not rngFind Is Nothing Then rngFind.EntireRow.Delete
Loop Until rngFind Is Nothing


Set rngFind = Nothing
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Slightly different approach. When deleting rows its better to start at the bottom and work up:

Code:
Sub DeleteRow()
    Dim lLastRow As Long, l As Long
    lLastRow = Range("B" & Rows.Count).End(xlUp).Row
    
    'Start at bottom row and work up finishing at row 2(change as required)
    For l = lLastRow To 2 Step -1
        If Range("B" & l) = "" Then Rows(l).Delete
    Next
End Sub
 
Upvote 0
Sir, you are a gent. Thank you so much. :)

You're welcome. I had a very similar issue a while back and got my answer here. When deleting rows it's always better to start at the last row with a value and work up.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,757
Members
448,991
Latest member
Hanakoro

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