I have been looking for a way to filter an Excel spreadsheet with more than two wildcards. I asked on StackOverflow previously if I could put more than two wildcards in to A
I'm going to stick to the !
prefix for the discards as that is a single character.
Dim h As Long, hstr As String 'put these at the top with the other var declarations
For v = LBound(vVALs, 1) To UBound(vVALs, 1)
For h = LBound(hierArray) To UBound(hierArray) 'I just prefer to work this way
hstr = hierArray(h) & Chr(42) 'stick a * on the end
If Left(hstr, 1) = Chr(33) And LCase(vVALs(v, 1)) Like LCase(Mid(hstr, 2)) Then 'starts with a ! and pattern matches the value
'matched a discard pattern. check to see if it was previously added
If dVALs.Exists(vVALs(v, 1)) Then _
dVALs.Remove vVALs(v, 1) 'get rid of it
Exit For 'discarded. do not keep checking to add
ElseIf LCase(vVALs(v, 1)) Like LCase(hstr) Then
If NOT dVALs.Exists(vVALs(v, 1)) Then _
dVALs.Add Key:=vVALs(v, 1), Item:=vVALs(v, 1)
End If
Next h
Next v
When creating the hierArray string, you can save a few cycles by putting the discard patterns first. That way, they will not get added and then subsequently removed.
Any further work in this areas would likely warrant switching to a full Regular Expression (regexp) pattern matching method.