Lets say I have a line like
************* ** 2345 Page 1 *****
how do I say if I find the word page then msgbox "Page"
Printable View
Lets say I have a line like
************* ** 2345 Page 1 *****
how do I say if I find the word page then msgbox "Page"
Here is a simple way.
VB Code:
Dim sStr As String sStr = "************* ** 2345 Page 1 *****" If InStr(1, sStr, "Page") > 0 Then MsgBox "Page" End If
Not sure what you mean, especially the like operator part but try:
:confused:Code:Dim tmp as String
If instr(mystring," Page ") > 0 then
tmp = mid(mystring,instr(mystring," Page ") )
tmp = left(tmp,instr(tmp,"*")-1)
msgbox tmp,vbOkOnly
End if
Jim : You are just being a little neater than i am. And i must agree never Hardcode the way i just hardcoded my code.
Doing the same sort of thing with the Like operator:The "*" wildcard character using Like means "any characters". Note that Like only tells you if the search string exists in the string. It doesn't tell you where the search string is located like InStr.VB Code:
MyString = "************* ** 2345 Page 1 *****" MySearch = "Page" If MyString Like "*" & MySearch & "*" Then MsgBox MySearch