View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RW RW is offline
external usenet poster
 
Posts: 49
Default Prevent getting all rows if Autofilter criteria doesn't exist

I am using the following code to cycle through criteria. However, if the data
does not match the criteria, I get all of the rows pasted to the new sheet.
How can this be prevented?
WshName, FCriteria and FCriteria2 are arrays. This code works when the data
contains the 2 criteria.

For a = y To z
Sheets(WshName(x)).Select
Range("B1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:=FCriteria(a)
Range("C1").Select
Selection.AutoFilter Field:=3, Criteria1:=FCriteria2(a)
Application.CutCopyMode = False
Range("A2:AV" & EndCell).Select
Selection.Copy
Sheets(WshName(a)).Select
Range("A2").Select
ActiveSheet.Paste
Range("A2").Select
Next a