I had the same problem, where I wanted to have a user-defined string for filtering, in which people can give the column and the filtervalue for multiple columns at once.
In this example the string users can define looks like:
"A,foo;B,bar;AD,beyond all recognition"
Or
"ColumnLetterOrIndex comma FilterValue Semicolon" Repeat.
and so on for any number of columns and values.
Code:
Public Function createFilter(filterstring as string) as Variant
Dim tempFilter As Variant
Dim realFilter As Variant
tempfilter = Split(filterstring, ";")
For i = LBound(tempfilter) To UBound(tempfilter)
ReDim Preserve realFilter(i)
realFilter(i) = Split(tempfilter(i), ",", 2)
'The 2 is needed if the filtervalue contains a comma on itself. Otherwise, it can be omitted.
Next i
createFilter = realFilter
End Function
The above function will create a multidimensional array from a string of which the values can be used with Excels autofilter from a string. Usage code:
Dim userFilter as Variant
userFilter = createFilter(userDefinedFilterString)
For i = LBound(userFilter) To UBound(userFilter)
'Note that here you'll have to convert the Columnletter to something numeral, unless the users define their column like 1, 2, 3 instead of A, B, C.
thefiltercolumn = Measure.filter(i)(0)
.AutoFilter thefiltercolumn, Measure.filter(i)(1)
Next i
When the filtervalues are equal to the "Is not equal to" or "contains", you can use excel's built-in way of doing that, e.g.
A,<>foo;B,*bar*;AD,>=5
Bad part: Multiple criteria on 1 column is not available like in the previous example.