I have a sheet where users can search for a term. I read the cells into an array and filter the data. They can choose wheater one term or both terms should be in the data.
If wksSearch.Cells(6, 2).Text = "" Then wksSearch.Cells(6, 2).Value = "xxx"
If wksSearch.Cells(7, 2).Text = "" Then wksSearch.Cells(7, 2).Value = "xxx"
If wksSearch.OLEObjects("chkBoth").Object.Value Then
aSearch(0) = "*" & wksSearch.Cells(6, 2).Text & "*" & wksSearch.Cells(7, 2).Text & "*"
aSearch(1) = "*" & wksSearch.Cells(7, 2).Text & "*" & wksSearch.Cells(6, 2).Text & "*"
Else
aSearch(0) = "*" & wksSearch.Cells(6, 2).Text & "*"
aSearch(1) = "*" & wksSearch.Cells(7, 2).Text & "*"
End If
wksdata.ListObjects("t_Data").Range.AutoFilter Field:=2, _
Criteria1:=aSearch, Operator:=xlFilterValues
My code works! But if I but a third search term, my code bloats. Is there a better solution? The xxx I could do with each cell in range. Easy, but the search array for the filter creates a headache. At least for me. :) I could do a loop but I think the must be a better filter option