Weird Excel error

sferguson524

Pattern Altitude
Joined
Feb 8, 2011
Messages
1,761
Location
Las Vegas
Display Name

Display name:
FormerSocalFlyer
For our excel gurus here... I have a userform with a combo box that filters the data on one sheet and moves it to another. All WAS working well and nothing changed in my code, now it's throwing an error 1004 autofilter method of range class failed when I select things in the combo box. See code below. Any help is appreciated!

Private Sub ComboBox3_Change()
Sheets("Filtered").UsedRange.ClearContents

Selection.AutoFilter

' turn off any autofilters that are already set
Sheets("Source").AutoFilterMode = False

' filter column C based on combo box selection
Selection.AutoFilter Field:=3, Criteria1:=ComboBox3.Value

' copy the visible cells to cell A1
Sheets("Source").UsedRange.SpecialCells(xlCellTypeVisible).Copy Range("Filtered!A1")

' Turn off any autofilters that are already set
Sheets("Source").AutoFilterMode = False
End Sub
 
Fixed it.. added one line of VBA code and it's good to go

Private Sub ComboBox1_Change()
Sheets("Filtered").UsedRange.ClearContents

Worksheets("Source").Activate <--- added this
Selection.AutoFilter
' turn off any autofilters that are already set
Sheets("Source").AutoFilterMode = False

' filter column A based on combo box selection
Selection.AutoFilter Field:=2, Criteria1:=ComboBox1.Value

' copy the visible cells to cell E8
Sheets("Source").UsedRange.SpecialCells(xlCellTypeVisible).Copy Range("Filtered!A1")

' Turn off any autofilters that are already set
Sheets("Source").AutoFilterMode = False
End Sub
 
Back
Top