franksirvent
Programmer
Hi there
I have spent hours on this and can't understand what's going on...
i have a combobox in EXCEL with 3 options, after any of the options is selected it runs the following code.
It runs ok HOWEVER the first time you run it, the user gets an error:
Error :1004, Failure on Method Autofilter of Range Class ?
Whatever that means?
If you ignore the message, nothing happens, and the next time you run the code, it correctly filters the rows....
Can anyone help? I am desperate?
thanks
Private Sub ComboBox1_Change()
On Error GoTo combobox1_error
Dim The_date As Long
The_date = Date
If ComboBox1 = "IN TRANSIT" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14,_ Criteria1:=">=" & The_date, Operator:=xlOr, Criteria2:=""
ElseIf ComboBox1 = "DELIVERED" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14, _Criteria1:="<=" & The_date, Operator:=xlAnd
ElseIf ComboBox1 = "ALL" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14,_ Criteria1:="<=" & The_date, Operator:=xlOr, Criteria2:=""
'.AutoFilter Field:=3, Criteria1:=">=" & The_date, Operator:=xlAnd
End If
Exit Sub
combobox1_error:
If Err.Number = 1004 Then
Else
End If
End Sub
I have spent hours on this and can't understand what's going on...
i have a combobox in EXCEL with 3 options, after any of the options is selected it runs the following code.
It runs ok HOWEVER the first time you run it, the user gets an error:
Error :1004, Failure on Method Autofilter of Range Class ?
Whatever that means?
If you ignore the message, nothing happens, and the next time you run the code, it correctly filters the rows....
Can anyone help? I am desperate?
thanks
Private Sub ComboBox1_Change()
On Error GoTo combobox1_error
Dim The_date As Long
The_date = Date
If ComboBox1 = "IN TRANSIT" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14,_ Criteria1:=">=" & The_date, Operator:=xlOr, Criteria2:=""
ElseIf ComboBox1 = "DELIVERED" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14, _Criteria1:="<=" & The_date, Operator:=xlAnd
ElseIf ComboBox1 = "ALL" Then
Selection.AutoFilter Field:=14
Selection.AutoFilter Field:=14,_ Criteria1:="<=" & The_date, Operator:=xlOr, Criteria2:=""
'.AutoFilter Field:=3, Criteria1:=">=" & The_date, Operator:=xlAnd
End If
Exit Sub
combobox1_error:
If Err.Number = 1004 Then
Else
End If
End Sub