Autofilter filter on combo change

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
I am trying to autofilter filter on combo change but it is giving runtime error 1004; autofilter if range class failed.
after that i want it to show in listbox1. which i think should be okay if this filtering works.

Thanks
Pedie

Code:
Private Sub ComboBox3_Change()
Sheet1.Select
Range("A1").Select
        Selection.AutoFilter
        Selection.AutoFilter Field:=1, Criteria1:=ComboBox3.Value
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
sorry for sort of bumpng up but it still wont work and i am spending lots of time i guess...
PHP:
Private Sub ComboBox3_Change()
Sheet1.Activate
Sheet1.Select
With ActiveSheet
            .AutoFilterMode = False
            .Range("A1:D1").AutoFilter
            .Range("A1:D1").AutoFilter Field:=1, Criteria1:=ComboBox3.Text
    End With
End Sub
 
Upvote 0
David, thanks for suggesting the links.
I went through all the link but wont let me come up with the working code:biggrin:

The code below first filters it and then give same error....
I am hoping someone would please write a running smooth code....
PS. I am running this code from userform1 combo change selection...
error:
PHP:
runtime error 1004; unable to get the current region property...of class range
PHP:
Private Sub ComboBox3_Change()
Dim x As String
x = ComboBox3.Value
Sheets("Sheet1").Activate
Rows(1).CurrentRegion.AutoFilter Field:=1, Criteria1:=x
End Sub
 
Last edited:
Upvote 0
Hi Pedie,

Not my area but try this.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox1_Change()<br>  <SPAN style="color:#00007F">With</SPAN> Sheet1.Range("A1")<br>    .AutoFilter<br>      MsgBox ComboBox1.Value <SPAN style="color:#007F00">'remove after testing!!!</SPAN><br>    .AutoFilter Field:=1, Criteria1:=ComboBox3.Value<br>  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Maybe i didnt know how to put them together...:biggrin: it still wont work at first but when i added
PHP:
on error resume next
on error goto 0
it is working....

Thanks for putting thoughts together.

Thanks Brian & everyone!

Pedie
 
Upvote 0
When you specify the Rowsource in a userform/combobox, you shouldn't use autofilter. During the change event, the combobox is trying to update the rowsource and is in conflict with the autofilter.

However, if you populate the combobox 'manually',

Code:
Private Sub UserForm_Initialize()

With Me.ComboBox1
For Each iRow In Sheet1.Range("A2:A7")
    .AddItem iRow
Next
End With

End Sub
Then

Code:
Rows(1).CurrentRegion.AutoFilter Field:=1, Criteria1:=ComboBox1.Value
works as expected.
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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