vba string function?

vbaNewby

Board Regular
Joined
Jan 26, 2011
Messages
138
Hello guru's,

I want to know if there is some type of string function that satisfies this example:

myString = "hel"

Cell1: "helloworld"
Cell2: "hel loworld"
Cell3: "hel lo world"

I want to return false for cell 1 but true for cell 2 and 3. Instr function (xlpart param???) will return true for all three. I basically want to return true if "hel" is a substring but its own word within a string.

I hope there is sometype of way to do this without having to write my own function!

Thanks in advance.
 
If you mean is InStr like SEARCH then yes.

As for the 3 conditions, what 3 conditions?

There's only one in that code.

Say this is ActiveCell

Cell1: "helloworld"
Cell2: "hel loworld"
Cell3: "hel lo world"

a = Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search(" " & "HEL" & " ", " " & UCase(ActiveCell) & " "))

False for Cell1 but True for Cell2 and Cell3

This is the solution you gave me but for some reason when I set a bunch of variables and run an if statement i.e.:

if a = "true" then
'do something
end if

its not catching within the if statments.

Wondering if:


InStr(1, " " & ActiveCell.Value & " ", " depreciation ", vbTextCompare) > 0




Will give me the same results (0 for cell1 and >0 for Cell2 and Cell3)

I can test it but there is a ton of code to change so I thought you might be able to give me answer.... :):eeek::eeek:
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I noticed it was your thread, I was pointing out that you have been given good advice there.:rofl:

What seems to have gone un-noticed is that you're using ActiveCell references, I do hope you're not selecting with a loop :eek:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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