specialcells method errors when criteria not found
Sub CleanCancelledChks()
Dim r As Range
With ActiveSheet
Set r = .Range(.Range("D2"), .Range("D" & _
Rows.Count).End(xlUp))
.Columns("D:D").AutoFilter Field:=1, Criteria1:="=*-*"
On Error Resume Next
Set r = r.SpecialCells(xlCellTypeVisible)
On Error goto 0
.AutoFilterMode = False
if not rng is nothing then _
r.EntireRow.Delete
End With
End Sub
--
Regards,
Tom Ogilvy
"ms" wrote in message
...
The sub below is used to check the D column for values with a negative
sign. If
the negative sign exists I want to delete the entire row. When there are
no
records with a negative sign in the D column, it returns a run-time error
1004 -
No cells were found. How do I rewrite this procedure so that the error is
not
returned when no cells with a negative are found but still deletes rows
when a
value has a negative sign? I understand that some Range object methods
require
that the range contain data. If the range does not contain data, the
method
fails. But what would be the proper way around this?
Sub CleanCancelledChks()
Dim r As Range
With ActiveSheet
Set r = .Range(.Range("D2"), .Range("D" & _
Rows.Count).End(xlUp))
.Columns("D:D").AutoFilter Field:=1, Criteria1:="=*-*"
Set r = r.SpecialCells(xlCellTypeVisible)
.AutoFilterMode = False
r.EntireRow.Delete
End With
End Sub
Thank you in advance for any advice.
mark
|