Please speed up my vba code! Deleting rows based on blank cells

jmelinda

New Member
Joined
Mar 9, 2011
Messages
23
Hey all,

I found this code on the board and was able to edit it to do what I need it to do but it is realllllly slow. Any suggestions to speed things up?

I have data in Columns A,B, & C. Most of Column C is blank. I want the rows where Column C is blank deleted, without deleting the entire row because I have buttons with macros assigned in Column D, E and F

Code:
 Dim rcell As Range
Dim rrange As Range
Dim i as Long
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Set rrange = Range("A2:C10000")
        For i = rrange.Rows.Count To 1 Step -1
            If rrange.Cells(i, 3).Value = "" Then
        rrange.Rows(i).Delete
    End If
    Next i

Any help is much appreciated! One way I thought that could speed it up is if the range was just the active range, but the number of rows is variable and I'm not sure how to account for that.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Instead of consuming 10000 rows, consume what is needed

i.e. lr finds the last row(lr) in the sheet with something in column A.

Code:
    Dim rcell As Range
    Dim rrange As Range
    Dim i As Long, lr As Long


    Application.ScreenUpdating = False
    Application.DisplayAlerts = False


    lr = Cells(Rows.Count, 1).End(xlUp).Row
    Set rrange = Range("A2:C" & lr)
    rrange.Select
    For i = rrange.Rows.Count To 1 Step -1
        If rrange.Cells(i, 3).Value = "" Then
            'rrange.Rows(i).Delete
            rrange.Cells(i, 1).Resize(1, 3).ClearContents
        End If
    Next i
 
Upvote 0
This should work for you and be quite a bit faster...

Code:
Sub DeleteOnlyABCforBlankCs()
  Dim LastRow As Long
  LastRow = Columns("A:C").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
  Intersect(Range("C1:C" & LastRow).SpecialCells(xlBlanks).EntireRow, Columns("A:C")).Delete xlShiftUp
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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