I have a large number of rows and columns (e.g. 500k rows and 20 columns) all filled with numbers.
I'm trying to delete all data in column I that has a certain value (e.g. less than or equal to 8), but when I try to use autofilter to delete the values, it freezes up Excel and doesn't delete.
It works quickly for data in column A. I remade similar data in a new sheet to make sure all cells were filled, no columns/rows were hidden etc.
Why is it freezing up for column I?
Sub DeleteRow()
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim rng As Range
Dim lastRow As Long
Set ws = ActiveWorkbook.Sheets("Sheet1")
'filter and delete all but header row which is in row 3
lastRow = ws.Range("I" & ws.Rows.count).End(xlUp).row
MsgBox lastRow
Set rng = ws.Range("I3:I" & lastRow)
' filter and delete all but header row
With rng
.AutoFilter Field:=1, Criteria1:="<=8"
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
' turn off the filters
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub