How to remove rows where cell is blank VBA

tawoodwa

New Member
Joined
Jan 9, 2017
Messages
17
Hi all, When I run this code I think it should find where the blank cells are in that range, and then delete the corresponding row, for some reason this throws excel in to a never ending loading loop or something, any ideas why or how i can fix this code?

Code:
With worksheet_to_process
    Dim LR As Long, i As Long
    LR = worksheet_to_process.Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
            With worksheet_to_process.Range("B" & i)
             If .Value = "" Then
             worksheet_to_process.Rows(i).Select
             Selection.Delete Shift:=xlUp
             i = i - 1
             End If
             
            End With
        Next i
    End With
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Here would be one way to write that with a similar method:

Code:
With worksheet_to_process
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If .Range("B" & i).Value = "" Then
            .Rows(i).Delete Shift:=xlUp
        End If
    Next i
End With
 
Upvote 0
If col B is values rather than formulae, you can replace all your code with
Code:
worksheet_to_process.Columns(2).SpecialCells(xlBlanks).EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,315
Members
448,886
Latest member
GBCTeacher

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