I created in VBA the following custom function and I'm using it in excel.
Public Function ISLIKE(ByVal sText As String, ByVal sPattern As String) As Boolean
If sText Like sPattern Then
ISLIKE = True
Else
ISLIKE = False
End If
End Function
The problem I have now is that I would like to check if a string is in the form of:
- First character is a number
- Second character is either a 'b' or a 's'
- Characters from the third onwards are optional
I can use '#' for the first character and '*' for the third character onwards but how can I specify whether the second character is either a 'b' or a 's'?
Thanks who those will reply.
Gabriele
Like "#[abc]*"
would match any string starting with a digit followed by any one of the characters inside the square brackets, and then any other [optional] content.See docs: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/wildcard-characters-used-in-string-comparisons
Note your function can be simpler as: