VBA filter and delete

ziad alsayed

Well-known Member
Joined
Jul 17, 2010
Messages
665
dear all

i am using th below code , and it is deleting about 19000 rows. the problem is that it is taking too long to delete them.

is there a way to make faster ?

Code:
sub try()
 Range("E1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$N$500000").AutoFilter Field:=5, Criteria1:="419", Operator:=xlFilterValues
    Range("A1").CurrentRegion.Offset(1, 0).Select
    Selection.EntireRow.Delete Shift:=xlUp
    Range("A1").Select
    ActiveSheet.Range("$A$1:$N$500000").AutoFilter Field:=5
     Range("E1").Select
    Selection.AutoFilter
    Columns("E:E").Delete
end sub

appreciate any help.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Untested, but try this on a copy of your workbook

Code:
Sub FilterDelete()
    Application.ScreenUpdating = False
    With Range("E1", Range("E" & Rows.Count).End(xlUp))
        .AutoFilter field:=1, Criteria1:="419"
        .Offset(1).EntireRow.Delete
        .AutoFilter
    End With
    Columns("E:E").Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
dear jeffreybrown

thanks , but both code a taking about 2 minutes and 40 seconds to finish the task.

any other idea?
 
Upvote 0
I just tested it on 500K rows and it ran in 3 seconds.

Do you have a lot of formulas in the worksheet?

If so try turning off calculations?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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