Hi,
I'm trying to delete rows based on a filter criteria, but I keep getting run-time error '1004' on the highlighted line. Here is what I have, can anyone help?
Sub DeleteRows()
Dim rTable As Range
Dim lCol As Long
On Error Resume Next
'Determine the table range
With Selection
If .Cells.Count > 1 Then
Set rTable = Selection
Else
Set rTable = .CurrentRegion
On Error GoTo 0
End If
End With
'Determine if table range is valid
If rTable Is Nothing Or rTable.Cells.Count = 1 Or WorksheetFunction.CountA(rTable) < 2 Then
MsgBox "Could not determine you table range."
Exit Sub
End If
rTable.AutoFilter Field:=21, Criteria1:="<0"
'Delete all rows that are NOT hidden by AutoFilter.
rTable.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End Sub
Bookmarks