is there any substring function in macro?

  • Thread starter Thread starter ashishprem
  • Start date Start date
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
 
Hi Ashishprem,

Look at the Instr function in VBA help.

If InStr(1, sStr, sStr2, vbTextCompare) > 0 Then _
MsgBox "Substring " & sStr2 & " found in " & sStr
 
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
 
Back
Top