AutoFilter Criteria Field in VBA

VIKTORIJA

New Member
Joined
Jun 20, 2002
Messages
3
I've recording an autofilter macro, then trying to add additional code in VBA. I'm trying to set the 'criteria' field to a data value - see following code - but VBA gives an error. Is there any way to force the criteria field to be want you want it to without hard-coding values??

Dim CostCenter As String
Selection.AutoFilter Field:=1, criteria1:= CostCenter
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You have to assign a value to Cost Center.

Or, if CostCenter is a named range, it does not have to be "dimmed" and the code would be :-

Selection.AutoFilter Field:=1, Criteria1:=Range("CostCenter")
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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