View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tony Tony is offline
external usenet poster
 
Posts: 1
Default VBA to stop if autofilter macro will wipe out all data

Hello - is there a way (I'm sure there is but I'm not smart enough to figure it out) to test whether a filter vba command will result in wiping out all data?

Sub test()

'delete rows that contain the word "paper" in Column D

Worksheets("Sheet1").Range("A1").AutoFilter Field:=4, Criteria1:="<*paper*"
Application.DisplayAlerts = False
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
Application.DisplayAlerts = True
ActiveSheet.ShowAllData

'end of "paper" check

'start next sequence ..etc
Columns("F:F").Select
etc, etc, etc

End Sub

In other words, if the data set does not have the keyword "paper" in Column D, then the above vba commands will delete all the data.

Looking for a macro that will precede the above to check whether Column D has any instances of the word "paper" *BEFORE* running the macro. If no "paper" exists in the Column, then the sequence should be bypassed and continue to the next set of vba commands immediately after (ie. jump immediately to Selecting Column F as shown above).

Thank you in advance!