Reputation: 61
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:
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
Upvotes: 2
Views: 170
Reputation: 166316
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.
Note your function can be simpler as:
Public Function ISLIKE(ByVal sText As String, ByVal sPattern As String) As Boolean
ISLIKE = sText Like sPattern
End Function
Upvotes: 4