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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

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,127,183
Messages
5,623,242
Members
415,957
Latest member
Newguy1924

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