Using AND/OR inside SEARCH

AD04

New Member
Joined
Jan 26, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hello. I want to SEARCH two strings (str1 AND str2) inside a cell with text. Also, I want to apply the following operations:
- str1 OR str2
- str1 but not str2
I'd appreciate if you could help me with this. Thanks.

lakers_g3_1005.0059_1006.0059_49k.xlsx
BCDEFG
1tweet_text"@Lakers""@MiamiHEAT""@Lakers " AND "@MiamiHeat ""@Lakers" OR "@MiamiHEAT" "@Lakers" but not "@MiamiHEAT"
2Big props to @JimmyButler and the @MiamiHEAT , they had more fight tonight. Hopefully that gives us the eye of the tiger back and we come back ready for war in game 4. Let’s get this! @Lakers #LakeShow #ForKobeTRUETRUE
3This @Lakers team DOES NOT know how to maintain intensity without facing adversity. Frustrating. @MiamiHEAT They should just let the fans know they don't plan on playing, and we can just tune into the following game.TRUETRUE
4@Lakers are playing like they don’t want to win this game. @JimmyButler leaving everything out on the floor. We are going to need more from @KingJames and @AntDavis23TRUEFALSE
5If the @Lakers lose today i will not be worried as we know what they are capable of. Its just disappointing that they can't pick up the slack.TRUEFALSE
6****. @Lakers let that one slip away. Why are they not pounding the BALL inside? We need more of @AntDavis23 otherwise it will be 2-2 soon.TRUEFALSE
7 Fr? Now they got confidence we gone have to destroy <U+B6> @AntDavis23 how you only put up 9 shots???? Y’all please reply. @miamiheat you did wellFALSETRUE
8Since the @Lakers are going to win anyways I think we can all agree, good for Miami. I'm happy they aren't rolling over. @MiamiHEAT #NBAFinalsTRUETRUE
9@lakers Give the Heat credit, they played their hearts out. They deserved to win. We didn't have the same energy and effort. Rest, make adjustments for next game and be ready to play!!!TRUEFALSE
Identification
Cell Formulas
RangeFormula
C2:C9C2=ISNUMBER(SEARCH("@Lakers ",B2))
D2:D9D2=ISNUMBER(SEARCH("@miamiheat", B2))
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Book1.xlsm
BCDEFG
1tweet_text"@Lakers""@MiamiHEAT""@Lakers " AND "@MiamiHeat ""@Lakers" OR "@MiamiHEAT" "@Lakers" but not "@MiamiHEAT"
2Big props to @JimmyButler and the @MiamiHEAT , they had more fight tonight. Hopefully that gives us the eye of the tiger back and we come back ready for war in game 4. Let’s get this! @Lakers #LakeShow #ForKobeTRUETRUETRUETRUEFALSE
3This @Lakers team DOES NOT know how to maintain intensity without facing adversity. Frustrating. @MiamiHEAT They should just let the fans know they don't plan on playing, and we can just tune into the following game.TRUETRUETRUETRUEFALSE
4@Lakers are playing like they don’t want to win this game. @JimmyButler leaving everything out on the floor. We are going to need more from @KingJames and @AntDavis23TRUEFALSEFALSETRUETRUE
5If the @Lakers lose today i will not be worried as we know what they are capable of. Its just disappointing that they can't pick up the slack.TRUEFALSEFALSETRUETRUE
6****. @Lakers let that one slip away. Why are they not pounding the BALL inside? We need more of @AntDavis23 otherwise it will be 2-2 soon.TRUEFALSEFALSETRUETRUE
7 Fr? Now they got confidence we gone have to destroy <U+B6> @AntDavis23 how you only put up 9 shots???? Y’all please reply. @miamiheat you did wellFALSETRUEFALSETRUEFALSE
8Since the @Lakers are going to win anyways I think we can all agree, good for Miami. I'm happy they aren't rolling over. @MiamiHEAT #NBAFinalsTRUETRUETRUETRUEFALSE
9@lakers Give the Heat credit, they played their hearts out. They deserved to win. We didn't have the same energy and effort. Rest, make adjustments for next game and be ready to play!!!TRUEFALSEFALSETRUETRUE
Sheet1
Cell Formulas
RangeFormula
C2:C9C2=ISNUMBER(SEARCH("@Lakers ",B2))
D2:D9D2=ISNUMBER(SEARCH("@miamiheat", B2))
E2:E9E2=AND(ISNUMBER(SEARCH("@Lakers ",B2)),ISNUMBER(SEARCH("@miamiheat", B2)))
F2:F9F2=OR(ISNUMBER(SEARCH("@Lakers ",B2)),ISNUMBER(SEARCH("@miamiheat", B2)))
G2:G9G2=AND(ISNUMBER(SEARCH("@Lakers ",B2)),ISERROR(SEARCH("@miamiheat", B2)))
 
Upvote 0
Hi AD04,

A slightly different approach.

AD04.xlsx
BCDEFG
1tweet_text"@Lakers""@MiamiHEAT""@Lakers " AND "@MiamiHeat ""@Lakers" OR "@MiamiHEAT" "@Lakers" but not "@MiamiHEAT"
2Big props to @JimmyButler and the @MiamiHEAT , they had more fight tonight. Hopefully that gives us the eye of the tiger back and we come back ready for war in game 4. Let’s get this! @Lakers #LakeShow #ForKobeTRUETRUETRUETRUEFALSE
3This @Lakers team DOES NOT know how to maintain intensity without facing adversity. Frustrating. @MiamiHEAT They should just let the fans know they don't plan on playing, and we can just tune into the following game.TRUETRUETRUETRUEFALSE
4@Lakers are playing like they don’t want to win this game. @JimmyButler leaving everything out on the floor. We are going to need more from @KingJames and @AntDavis23TRUEFALSEFALSETRUETRUE
5If the @Lakers lose today i will not be worried as we know what they are capable of. Its just disappointing that they can't pick up the slack.TRUEFALSEFALSETRUETRUE
6****. @Lakers let that one slip away. Why are they not pounding the BALL inside? We need more of @AntDavis23 otherwise it will be 2-2 soon.TRUEFALSEFALSETRUETRUE
7 Fr? Now they got confidence we gone have to destroy <U+B6> @AntDavis23 how you only put up 9 shots???? Y’all please reply. @miamiheat you did wellFALSETRUEFALSETRUEFALSE
8Since the @Lakers are going to win anyways I think we can all agree, good for Miami. I'm happy they aren't rolling over. @MiamiHEAT #NBAFinalsTRUETRUETRUETRUEFALSE
9@lakers Give the Heat credit, they played their hearts out. They deserved to win. We didn't have the same energy and effort. Rest, make adjustments for next game and be ready to play!!!TRUEFALSEFALSETRUETRUE
10This has neitherFALSEFALSEFALSEFALSEFALSE
Sheet1
Cell Formulas
RangeFormula
C2:C10C2=ISNUMBER(SEARCH("@Lakers ",B2))
D2:D10D2=ISNUMBER(SEARCH("@miamiheat", B2))
E2:E10E2=ISNUMBER(SEARCH("@Lakers ",B2)+SEARCH("@MiamiHEAT",B2))
F2:F10F2=OR(ISNUMBER(SEARCH("@Lakers ",B2)),ISNUMBER(+SEARCH("@MiamiHEAT",B2)))
G2:G10G2=AND(ISNUMBER(SEARCH("@Lakers ",B2)),ISERR(SEARCH("@MiamiHEAT",B2)))
 
Upvote 0
Some more options.

21 02 11.xlsm
BCDEFG
1tweet_text@Lakers@MiamiHEAT@Lakers AND @MiamiHeat @Lakers OR @MiamiHEAT @Lakers but not @MiamiHEAT
2Big props to @JimmyButler and the @MiamiHEAT , they had more fight tonight. Hopefully that gives us the eye of the tiger back and we come back ready for war in game 4. Let’s get this! @Lakers #LakeShow #ForKobeTRUETRUETRUETRUEFALSE
3This @Lakers team DOES NOT know how to maintain intensity without facing adversity. Frustrating. @MiamiHEAT They should just let the fans know they don't plan on playing, and we can just tune into the following game.TRUETRUETRUETRUEFALSE
4@Lakers are playing like they don’t want to win this game. @JimmyButler leaving everything out on the floor. We are going to need more from @KingJames and @AntDavis23TRUEFALSEFALSETRUETRUE
5If the @Lakers lose today i will not be worried as we know what they are capable of. Its just disappointing that they can't pick up the slack.TRUEFALSEFALSETRUETRUE
6****. @Lakers let that one slip away. Why are they not pounding the BALL inside? We need more of @AntDavis23 otherwise it will be 2-2 soon.TRUEFALSEFALSETRUETRUE
7 Fr? Now they got confidence we gone have to destroy <U+B6> @AntDavis23 how you only put up 9 shots???? Y’all please reply. @miamiheat you did wellFALSETRUEFALSETRUEFALSE
8Since the @Lakers are going to win anyways I think we can all agree, good for Miami. I'm happy they aren't rolling over. @MiamiHEAT #NBAFinalsTRUETRUETRUETRUEFALSE
9@lakers Give the Heat credit, they played their hearts out. They deserved to win. We didn't have the same energy and effort. Rest, make adjustments for next game and be ready to play!!!TRUEFALSEFALSETRUETRUE
Search Text
Cell Formulas
RangeFormula
C2:D9C2=COUNT(SEARCH(C$1,$B2))=1
E2:E9E2=COUNT(SEARCH(C$1,B2)+SEARCH(D$1,B2))=1
F2:F9F2=COUNT(SEARCH(C$1,B2),SEARCH(D$1,B2))>0
G2:G9G2=COUNT(SEARCH(C$1,B2))&COUNT(SEARCH(D$1,B2))="10"
 
Upvote 0
Solution
Thanks for the help, aRandomHelper. I am wondering how implement nesting one command inside the other? Is it by hit and trial or do you master individual commands and then attempt nesting?
 
Upvote 0
Appreciate the help, Peter_SSs. Didn't think about nesting SEARCH inside COUNT. Didn't exactly get the last command. Why ="10" in the end?
 
Upvote 0

Thanks for the help, Toadstool. I want to ask about the command for the OR operation.​

=OR(ISNUMBER(SEARCH("@lakers ",B2)),ISNUMBER(+SEARCH("@MiamiHEAT",B2)))

What's the logic behind using + before the second SEARCH?
 
Upvote 0
master individual commands and then attempt nesting
I usually go about forming formulas in pieces, so this would be my approach.

For the case of AND() and OR(), I would make sure each component work correctly before inserting them.
If it's going to be a really long nesting of IFs, sometimes I do it on a notepad first, spreading the formula across multiple lines for visibility's sake, then form it up and throw it into Excel. Probably sounds weird but it works for me.
 
Upvote 0
Appreciate the help, @Peter_SSs. Didn't think about nesting SEARCH inside COUNT.
You are welcome. Glad to contribute ideas.


Didn't exactly get the last command. Why ="10" in the end?
If Lakers is found, SEARCH will produce a single number and COUNT will count that number which would produce a 1.
If MiamiHEAT is not found, SEARCH will produce an error so COUNT will return 0 (zero).
The formula concatenates (as a string) the two relevant values which would produce "10"

If both Lakers & Miami were found the result would be "11" (so we could have used a formula like this for column E as well :))
If neither found the string would be "00"
and if Lakers not found but Miami is then "01"
 
Upvote 0

Thanks for the help, Toadstool. I want to ask about the command for the OR operation.​

=OR(ISNUMBER(SEARCH("@lakers ",B2)),ISNUMBER(+SEARCH("@MiamiHEAT",B2)))

What's the logic behind using + before the second SEARCH?

It was a leftover from copying the E2 formula, but it still works.

I was hoping one of your requests was an "either but not both" so I could use XOR.
I don't think I've ever used that in Excel, but I remember using it almost 50 years ago in Assembler. ;)
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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