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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:

Code:
ActiveSheet.Range("$A$1:$Z$5000").AutoFilter Field:=8, Criteria1:="*" & New_Company & "*", Operator:=xlFilterValues
 
Upvote 0
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 :)
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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