VBA filtering array

jon1315

New Member
Joined
Jun 16, 2020
Messages
45
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
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,563
Office Version
  1. 365
Platform
  1. Windows
You can only use two criteria, unless doing an exact match.
 

jon1315

New Member
Joined
Jun 16, 2020
Messages
45
Office Version
  1. 365
Platform
  1. Windows
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..!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,563
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,610
Messages
5,625,814
Members
416,138
Latest member
Pizzaman22

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
Top