jrc
jrc

Reputation: 13

Excel 2013 VBA Like condition with colon won't work

The value of gettxt = 'ATCH 6: Page 2 of 2

gettxt values are from text formatted cells.

I cannot get the following Like condition to be true.

If LCase(gettxt) Like "*atch #*:" Then ...

Suggestions on how to fix the Like statement are appreciated.

Upvotes: 1

Views: 67

Answers (1)

hod
hod

Reputation: 761

You're just missing one more "*" after the colon. Your condition states that there shouldn't be anything AFTER the colon, but your "gettxt" value has something in it after that. So the correct condition should be:

If LCase(gettxt) Like "*atch #*:*" Then

Full working version:

Sub test()

gettxt = "ATCH 6: Page 2 of 2"

If LCase(gettxt) Like "*atch #:*" Then
    Debug.Print "Working!"
Else
    Debug.Print "Not Working!"
End If

End Sub

Hope this helps!

Upvotes: 1

Related Questions