Runtime error 1004...Autofilter method of rangefailed....

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Why is this error happening...i think it is coded correctly...

Code:
[/FONT]
[FONT=Courier New]Sub filterme()
Dim x As String
Dim lr&
x = ActiveSheet.ComboBox1.Value
lr = Sheets("HOME").Range("K" & Rows.Count).End(xlUp).Row[/FONT]
[FONT=Courier New]ActiveSheet.Range("K1:N" & lr).Select
ActiveSheet.AutoFilterMode = False
ActiveSheet.Range("K1:N" & lr).AutoFilter Field:=4, Criteria1:=x
Range("K1:N" & lr).SpecialCells(xlCellTypeVisible).Copy Range("B2")
ActiveSheet.AutoFilterMode = False
End Sub[/FONT]
[FONT=Courier New]
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
It worked for me. What line is producing the error (Stepping thru it - using F8)?
 
Upvote 0
ActiveSheet.Range("K1:N" & lr).AutoFilter Field:=4, Criteria1:=x
It error in the above line.

Home sheet is the active sheet...

Thanks again for helping.

It works for me too if I f8 but when I run, It errors...
This is connected to combo box whose change events fires this vba...
 
Upvote 0
For some reason the AutoFilter is causing the ComboBox's Change event procedure to run again. Try disabling events like this:

Code:
Dim EventsDisabled As Boolean
 
Private Sub ComboBox1_Change()
    If EventsDisabled = True Then Exit Sub
    EventsDisabled = True
    Call filterme
    EventsDisabled = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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