I just came across an “Invalid Pattern String” error while use the Like keyword to fill a listbox. I thought Like was more robust than that. Here’s what msdn has to say about it.
I changed my code to this:
Dim sh As Worksheet
On Error GoTo ErrHandler
For Each sh In ThisWorkbook.Sheets
If UCase(sh.Name) Like UCase(" * " & sFilter & " * ") Then
Me.lbxSheets.AddItem "Invalid Pattern"
Instead of loading the matching sheets, I load “Invalid Pattern” when an error is encountered. I hope I don’t get any other errors.
I stumbled on this when I mistyped an open bracket ([) for a filter. It doesn’t like open brackets without its closing cousin. I did note, however, that
"" Like "*[*", that is an empty string for the left hand side, does not produce an error, just False.