VBA filtering array

jon1315

Board Regular
Joined
Jun 16, 2020
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi All
I'm looking to filter with the criteria being an array - can't quite get it to work.

Simple example below - where am I going wrong?

Thanks in advance!
Jon

VBA Code:
Sub test()
Dim Narrative As Variant
Narrative = Array("*OPENING*", "*CLOSING*", "*VALUE*")
Range("A2:H100").AutoFilter FIELD:=4, Criteria1:=Narrative
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You can only use two criteria, unless doing an exact match.
 
Upvote 0
I have come across the 2 criteria limitation before but was trying to come up with a way around it!

Is there a way to do a VBA equivalent of an advanced filter? Would that method work? In reality there's probably 7/8 wildcards I need to delete from a list, and it wouldn't be the end of the world to do it long handed but, an opportunity to learn & that..!
 
Upvote 0
Yes, it can be done using advanced filters, just turn on the macro recorder & record yourself setting up & using an advanced filter, that way you will have the code.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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