Efficiency - DELETE ROWS

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
Hello Guys!

Help me speed up my code please.

I need to remove rows that contains specific pair of values in columns L and M.
80 and 1, 80 and 01, 80 and 03, 80 and 10 (01 and 1 are different - its all TEXT)

ex.

[TABLE="width: 500"]
<tbody>[TR]
[TD]L[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]80[/TD]
[TD]01[/TD]
[/TR]
[TR]
[TD]80[/TD]
[TD]03[/TD]
[/TR]
[TR]
[TD]80[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]80[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


My working code is :

Code:
    Dim Fil As Long
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False


    Fil = Range("A" & Rows.count).End(xlUp).row
        With Range("A1:N" & Fil)
          .AutoFilter
          .AutoFilter field:=12, Criteria1:="80"
          .AutoFilter field:=13, Criteria1:=Array( _
                "01", "03", "1", "10"), Operator:=xlFilterValues
          .Offset(1, 0).SpecialCells(xlCellTypeVisible).Rows.Delete
        End With
    Selection.AutoFilter
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

This code works fine but the trick is that I have over 1.000.000 records and can it be done faster with better code??

Best Regards
W.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
just on a rough calculation, with over a 1 meg in rows, the best time would be appx 5 seconds. If you are beating that, then you are pretty much optimal.
 
Upvote 0
commonly for deleting entire rows of visible cells with large datasets the slowness is overcome if the data is sorted

if it can be done, sort on columns L & M to create just a few contiguous blocks to delete - instead of perhaps thousands without sorting

resort to a different (starting) order after doing the deleting, if required
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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