VBA If variable contains...

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Hi,

How could I get a program to react if a variable contained something.

Eg.

Code:
a = "hello world"

if a contains "hello" then
    msgbox a
end if

Cheers
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Contain something or start with something? Anyway, have a look at Like operator:
Code:
a = "hello world"

If a Like "hello*" Then
    MsgBox a
End If
 
Upvote 0
Ah yea that’s what I want.

I'm doing a search program and the user is going to enter a name. I need it to search for fields where it might contain other words or just an initial.

I've not used the like operator before.

Cheers!
 
Upvote 0
Put Option Compare Text as the first line in your module.
 
Upvote 0

Forum statistics

Threads
1,223,315
Messages
6,171,416
Members
452,401
Latest member
Stereonix

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