string within a string

ian watkins

New Member
Joined
Feb 4, 2003
Messages
28
Is there an easy way using VBA to check whether a string is contained in another string

Cheers
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
WELCOME TO THE BOARD!

Try looking at the InStr function.

Try this:

Code:
Sub StringTest()
Dim MyString As String
    MyString = "This is a test"
    'Find the word "test" in the variable MyString and indicate where it is in the string
    MsgBox InStr(1, MyString, "test")
    'Since "Won't be there" isn't part of MyString, the value will be zero
    If InStr(1, MyString, "Won't be there") = 0 Then
        MsgBox "Won't be there isn't part of your string"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,431
Members
451,705
Latest member
Priti_190

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