Opposite of "Like" in VBA

R

Ryan

I have created a function (code below) however I want to change the "Like"
part to "not like" however this does not work. Can someone please advise what
the statement should be i.e the opposite of "Like". Thanks (from someone who
has been experimenting with VBA for 1 week)

Function One3Numbers(NumCalled As Variant) As Variant
If NumCalled Like "13*" Then
One3Numbers = "a 13 number"
Else
One3Numbers = "is not a 13 number"
End If
End Function
 
A

Allen Browne

Use:
If Not NumCalled Like "13*" Then

However, remember to handle Nulls. A Null doesn't match anything: it isn't
like anything, and it doesn't evaluate to true when you ask if it's not like
anything. See Errors 5 and 6 in this article:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html
 
Top