Delete Visible Rows

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,057
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code and is working all fine, but the only problem is its taking a lot of time, just for 2000 rows it took 20 min.
is there a way as how can i faster this process. I do have formula in other sheet . Any idea.

Its just auto filter the row, and deletes the visible rows.

VBA Code:
[CODE=vba]Sub filtration()
Dim x As Long

Application.ScreenUpdating = False

    With ActiveSheet
        'Remove any filters
        If .AutoFilterMode Then .AutoFilterMode = False
        'Define last used row in column 5/"E"
        x = .Cells(.Rows.Count, 49).End(xlUp).Row
              
        With .Range("AW1").Resize(x)
            'Apply filter to range E1:Ex
            .AutoFilter

            'Filter for "A"
            .AutoFilter Field:=1, Criteria1:="0"

            'Turn off warning pop-up message
            Application.DisplayAlerts = False

            'Offset by 1 from E1 (keep header), delete visible rows
            .Offset(1).Resize(x - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete 'Here how can we faster the same'

            'Turn on warning pop-up message
            Application.DisplayAlerts = True
        End With
        
        'Remove filter
        .AutoFilterMode = False
    End With
Application.ScreenUpdating = True
End Sub

[/CODE]
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
if you sort your data, and then delete that can be quicker
 
Upvote 0
I did tried that as well, but still it takes time.
 
Upvote 0
ow many formulas relate across the sheet
 
Upvote 0
when you step through the routine, does it step out and back as parts change

you might add Application.EnableEvents = False

and make true at the end otherwise you can loose control of the screen

also consider taking display alerts outside of the loop, you are turning off and on as it runs
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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