Excel VBA: Finding a String in a String

Converemon

New Member
Joined
May 23, 2014
Messages
15
Suppose I have two strings: U98 & K11+P46+M67+U98 ..All I need to know is how to return True if the first string is in the second or False if it is not. I have been trying to use this:

Code:
str1Mask = curStrCell.Value Like strCell.Value
If str1Mask = True
    'Do whatever
End If

Where curStrCell is the second string and strCell is the first; even though I've tried it in the opposite order. Can anyone tell me what I'm doing wrong or suggest a better way to do this?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
When comparing strings an asterisk is a wild card. So you would code as follows:

Code:
str1Mask = [B][COLOR="#0000FF"]"*"[/COLOR][/B] & curStrCell.Value & [B][COLOR="#0000FF"]"*"[/COLOR][/B] Like strCell.Value
 
Upvote 0
My apologies, I feel as if I didn't make my problem as clear as it could've been. There are five columns of the substrings that must either match the parent string or be empty. If even one substring does not match the whole statement must be False. So basically if "U98, K54, L21, "", "" " can be found in "L21+V06+K54+U98+M67" then it should return True. But, it could also be "!U98, K54, !L21, "", "" " which would return False because of the "!". However, I think my biggest problem is that it could be "!M43, !U67, "", "", "" " against "L21+V06+K54+U98+M67" because these strings are not found in the parent string but the statement is still True. I hope this makes things more clear as I've been trying to use "Like" and "InStr" in a large variety of ways. Thanks.

Also, I have tried to implement both Gavin's and Marcelo's techniques with no success, yet.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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