is there any substring function in macro?

A

ashishprem

Hi All,
I am new to macro. May be its a sily question but still. I have a
string "B&F OFA 12". I wanna to know whether OFA is present in the
string or not. I mean substring...
Please help me out..
Thanks n Regards,
Ashish
 
N

Norman Jones

Hi Ashishprem,

Look at the Instr function in VBA help.

If InStr(1, sStr, sStr2, vbTextCompare) > 0 Then _
MsgBox "Substring " & sStr2 & " found in " & sStr
 
G

Guest

use INSTR() this returns a 0 if the substring doesn't exist or the number of
the letter in the string where it occurs. You could also use the LIKE method

if INSTR(text, thisbit)> 0 Then
msgbox thisbit & " is in " & text
Else
msgbox thisbit & " is not in " & text
End if

if text LIKE "*" & thisbit & "*" Then
msgbox thisbit & " is in " & text
Else
msgbox thisbit & " is not in " & text
End if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top