Macro to autofilter a worksheet...

teebruin

New Member
Joined
Mar 28, 2002
Messages
38
I have a combobox and a command button. I want to allow the user to make a selection with the combo box and then autofilter the worksheet based on the selection, i.e. if S1 is selected in combobox1, then I want to click the commandbutton and autofilter the worksheet, column H using the value of the combo box as the criteria.

I used the following code for the click command:

selection.autofilter
selection.autofilter Field:=8, Criteria:=combobox1.value

I get a run-time error stating autofilter method of range class failed.

Any ideas to help me accomplish my goal?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Tommy Bak

Active Member
Joined
Feb 25, 2002
Messages
288
Hi
It could be becourse your selection is your combobox. Change the selection.

range("H1").select
selection.autofilter Field:=8, Criteria:=combobox1.value


regards Tommy
 

Forum statistics

Threads
1,181,899
Messages
5,932,690
Members
436,851
Latest member
masthomas

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