AutoFilter with Variable

AlexCS

Board Regular
Joined
Oct 31, 2011
Messages
78
Hi everyone,

Could someone please explain to me why the following does not work?

ActiveSheet.Range("$A$1:$Z$5000").AutoFilter Field:=8, Criteria1:=Array("*New_Company*"), Operator:=xlFilterValues

New_Company is a variable of type String that takes different values via an InputBox

How could I correctly formulate the instruction to get to the desired result - that is filter my tab on a variable to get all the entries containing that variable in their name?

Many thanks,

Alex
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
ActiveSheet.Range("$A$1:$Z$5000").AutoFilter Field:=8, Criteria1:="*" & New_Company & "*", Operator:=xlFilterValues
 

AlexCS

Board Regular
Joined
Oct 31, 2011
Messages
78
Thanks a lot Andrew! I had instructed my users to input the variable directly between stars but this works as well and I've learned something new :)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,087
Messages
5,599,654
Members
414,325
Latest member
kfg1287

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