Auto filter - Error Handler if criteria is missing

pjkaphlen

Board Regular
Joined
Aug 3, 2015
Messages
85
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hello VBA Wizards,

Would like to request for your assistance again to solve another VBA problem. I'm sure you have a solution for this, but would like to ask for your guidance on this.

PROBLEM:
I'm creating a macro which will filter 4 criteria(not necessary true for all 4) on 10 excel workbooks and copy the filtered contents on a separate workbook.

Code:
ActiveSheet.Range("A1:W" & LastRow).AutoFilter Field:=9, Criteria1:=Array("INDUSTRIES", "SPEEDY", "ELECTRONICS", "WORLD"), Operator:=xlFilterValues

As seen from above there are four criteria namely: INDUSTRIES, SPEEDY, ELECTRONICS, WORLD. But the problem is, NOT all Excel Workbooks have all 4 criteria. Possible that on the 1st workbook I will only have INDUSTRIES and WORLD, 2nd workbook will only have INDUSTRIES and SPEEDY while 3rd workbook contains ELECTRONICS and WORLD. The code above would simply result to error if one workbook does not contain either one of the criteria.

Ultimately, is there a way to handle such case with If error?

I am thinking of doing a "scan" of the column first and see if the criteria are there or not and run a if code after that.

Any guidance would be greatly appreciated!

Thank you so much!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What error do you get & what line of code is highlighted?
What you have supplied should not create an error.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top