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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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