Alternative to Find Function in VBA

Lochnagar

New Member
Joined
Jan 28, 2008
Messages
43
Hi,

I was hoping that someone might be able to point me in the right direction with regards to a vba problem that I have. Basically, is it possible to search for a particular text substring within a string e.g.

Searching for substring "is my" within
String = "this is my string"

I appreciate I could do this in excel with the 'Find' function, but I hoping that I might be able to do it in vba. Or put simply what is the vba equivalent of excels Find function?

Any help or advice, as always, will be hugely appreciated.

Thanks in advance,
Lochnagar
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
If Instr(Range("A1").Value,"my string") > 0 Then
' value being searched for is contained in string being searched
Else
' value being searched for is NOT contained in string being searched
End If
 
Upvote 0
Try InStr

Code:
Sub test()
Dim myString As String
myString = "this is my string"
MsgBox IIf(InStr(myString, "is my") > 0, "Found", "Not found"), vbInformation
End Sub
 
Upvote 0
Brilliant thanks VoG and doofusboy (thou, I'm the one feeling like a doofus:)) that's just what I was needing.

Thanks again, you help is very much appreciated.

Lochnagar.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top