If all you need to do is to delete rows with blanks in column A , you don't need to filter, just:
Sub DeleteRows()
Range("A:A").Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
Question
I have the following code in my Excel sheet:
Sub DeleteRows
'Filter CMReport to delete (Blank) rows.
With ActiveSheet
.AutoFilterMode = False
.Range("A1:G1").AutoFilter
.Range("A1:G1").AutoFilter Field:=1, Criteria1:="="
.Range("A1:G1").Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
End Sub
It will filter the blank rows but will not delete them... it says that no rows are selected. What am I doing wrong.
Solution
If all you need to do is to delete rows with blanks in column A , you don't need to filter, just:
Sub DeleteRows()
Range("A:A").Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
OTHER TIPS
I would do this one:
Sub DeleteRows()
With ActiveSheet
.AutoFilterMode = False 'remove filter
With .Range("A:G")
.AutoFilter Field:=1, Criteria1:="="
On Error Resume Next ' for the case when there is no visible rows
.Resize(.Rows.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
End With
.AutoFilterMode = False 'remove filter
End With
End Sub