View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ms ms is offline
external usenet poster
 
Posts: 5
Default specialcells method errors when criteria not found

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