I am trying to create dynamic filters based on varying conditions and different criteria. Suppose the user is providing some data like
Sal>100 and sal<1000 and not equal to 500
I am dynamically able to create the string with all the criteria and values and store that in a variable.
Here is the example:
Filter_con has the following value
Criteria1:=">10", Operator:=xlAnd, Criteria2:="<100000000",Operator:=xlFilterValues
When I am trying to execute the code
Selection.AutoFilter Field:=235, Filter_con
I am getting the error:
Run time error: 1004 AutoFilter method of range class failed.
Here is the code
t_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Range("A3:XFD" & t_lastrow).Select
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or
ActiveSheet.FilterMode Then
Selection.ShowAllData
End If
Filter_Con=">10","<100000000"
Filter_numric_data = Split(Replace(Filter_Con, Chr(34), ""), ",")
UBU = UBound(Filter_numric_data)
Filter_Con = ""
For i__ = 0 To UBU
If i__ <> UBU Then
MsgBox (Filter_numric_data(i__))
Filter_Con = Filter_Con & " Criteria" & i__ + 1 & ":=" &
Filter_numric_data(i__) & ", Operator:=xlAnd,"
Else
Filter_Con = Filter_Con & " Criteria" & i__ + 1 & ":=" &
Filter_numric_data(i__)
End If
Next
Range("A3:XFD" & t_lastrow).Select
Selection.AutoFilter Field:=Filter_Field & "," & Filter_Con
@- this will put a message in their inbox. For example: @satyanarayanavanka. Otherwise, comments are directed only at your inbox, as the person who asked the question.