Deleting Rows faster, if cell contains

Levi22

New Member
Joined
Feb 27, 2014
Messages
26
hi guys

I am using the code below to delete rows, the problem is that this is very slow.
Is there a way i can perform this a bit faster?

Thank you



PHP:
Sub DeleteRows()
    Dim c As Range
    Dim SrchRng
     
    Set SrchRng = ActiveSheet.Range("i10", ActiveSheet.Range("i1654").End(xlUp))
    Do
        Set c = SrchRng.Find("", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Maybe:

Code:
Sub Levi22()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Range("I9:I1654").AutoFilter 1, "="
Range("I10:I1654").SpecialCells(xlCellTypeVisible).EntireRow.Delete
ActiveSheet.AutoFilterMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You can make just about any code run significantly faster by turning off calculations / screenupdating / events

Code:
Dim PrevCalc As Variant
With Application
    .EnableEvents = False
    .ScreenUpdating = False
    PrevCalc = .Calculation
    .Calculation = xlCalculationManual
End with

'the rest of your code here

'now reset back to true

With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .Calculation = PrevCalc
End with
 
Upvote 0
Try this:
Code:
Sub DeleteRows()
    Dim SrchRng As Range
     
    Set SrchRng = ActiveSheet.Range("i10", ActiveSheet.Range("i1654").End(xlUp))
    SrchRng.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Thank you very much guys.

Joe: The cells I am referring to have formulas in them so this code doesn't work. Tried your code when the formulas are removed and it works perfectly fine.

JonMo1: I have tried using your solution but nothing happens.

John: Your tweek did the trick. Appcreciated, thank you very much.
 
Upvote 0
The cells I am referring to have formulas in them so this code doesn't work.
Ah, that was an important bit of information that you might have wanted to mention! ;)
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,173
Latest member
Kon123

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