Hello forum,
The line that is meant to apply the autofilter to the range A5 to Q & LastRow is not executing as expected.
The error message I get is "can't be applied to the selected range. Select a single cell in a range and try again."
How can I correct this?
Code
Sub AFDeleteRows()
Dim LastRow As Long
LastRow = Cells(Rows.Count, 10).End(xlUp).Row
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
'The line below is returning the error
ws.Range("A5:Q" & LastRow).AutoFilter Field:=9, Criteria1:=""
Application.DisplayAlerts = False
ws.Range("I5:I" & LastRow).SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
End Sub
Display More
Happy New Year!