View Full Version : like comparason
chungtinhlak
03-12-2009, 08:35 AM
how come this doesn't work?
Example
in my cell B5, I have Thaison
How come my code doesn't come back as a yes
Sub test()
If Range("B5").Value Like "ai" Then
MsgBox ("yes")
End If
End Sub
tpoynton
03-12-2009, 08:52 AM
need wildcards to indicate the text can occur anywhere?
Sub test()
If Range("B5").Value Like "*ai*" Then
MsgBox ("yes")
End If
End Sub
mdmackillop
03-12-2009, 02:41 PM
Continuation moved to new thread (http://vbaexpress.com/forum/showthread.php?t=25647)
Chris Bode
03-12-2009, 09:25 PM
As you are searching within a string, you need wild cards * and * as
add a command button from control box and paste following codes on the code window
Private Sub CommandButton1_Click()
If Sheet1.Range("B5").Value Like "*nu*" Then
MsgBox "Yes"
End If
End Sub
Now execute the codes and check the result
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.