I have a UserForm where users can select the range of numbers to filter the date from: ComboBox1 (select the operator, eg >=), Textbox3 (select number), ComboBox2 (select the operator, eg <=), , TextBox4 ((select number).
Furthermore, there is a Checkbox7 where users can tick to choose to include a text string in the filter too. (There is a combination of both strings and numbers in the column.)
Only the first 2 and last if/elseif condition works, the others do generate a filtered selection, but only the text string (if Checkbox7 = True) and numbers that meet the criteria in ComboBox2 & TextBox4 appear.
I don't understand how autofilter arrays with a range of numbers work. I'm also not sure whether to use xlAnd or xlOr when filtering a range of numbers with multiple criteria..
Any suggestions on how to make the code less verbose would be great.
Dim arr_Filter() As Variant
Dim arr_moreless() As Variant
Dim Age_Day As Integer: Age_Day = 10
arr_Filter = Array(ComboBox1 & TextBox3, ComboBox2 & TextBox4)
arr_moreless = Array(ComboBox2 & TextBox4, "No Date")
If ComboBox2.Value = "" And TextBox4.Value = "" And CheckBox7 = True Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=ComboBox1 & TextBox3, Operator:=xlOr, Criteria2:="No Date"
ElseIf ComboBox2.Value = "" And TextBox4.Value = "" And CheckBox7 = False Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=ComboBox1 & TextBox3, Operator:=xlFilterValues
ElseIf ComboBox1.Value = "<=" And ComboBox2.Value = ">=" And CheckBox7 = True Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=arr_Filter, Operator:=xlOr, Criteria2:="No Date"
ElseIf ComboBox1.Value = "<=" And ComboBox2.Value = ">=" And CheckBox7 = False Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=arr_Filter, Operator:=xlFilterValues
ElseIf ComboBox1.Value = ">=" And ComboBox2.Value = "<=" And CheckBox7 = True Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=ComboBox1 & TextBox3, Operator:=xlAnd, Criteria2:=arr_moreless
ElseIf ComboBox1.Value = ">=" And ComboBox2.Value = "<=" And CheckBox7 = False Then
FilterRange.AutoFilter Field:=Age_Day, Criteria1:=ComboBox1 & TextBox3, Operator:=xlAnd, Criteria2:=ComboBox2 & TextBox4
End If