简体   繁体   中英

Excel 2016: Searching for multiple terms in a cell

I'm trying to do a search for multiple strings in a cell with an OR-condition in Excel 2016.

Eg I have a string abcd1234 and I want to find ab OR 12 .

I'm using the german version where the function SEARCH is called SUCHEN and it should behave the same way.

I found this answer which suggests this solution:

SEARCH({"Gingrich","Obama","Romney"},C1) .

I also found this website which suggests the same syntax:

SEARCH({"red","blue","green"},B5)

Same with this website :

SEARCH({"mt","msa","county","unemployment","|nsa|"},[@Tags])

So they basically say make a list of search terms separated by commas enclosed by curly braces and you're good.

But putting these into Excel 2016 just results in the usual meaningless Excel error message which says there was an error with the formula and it's always highlighting the whole part in curly braces.

Taking the first example the only way I could get Excel to not throw its error message was to change the syntax like this:

=SEARCH({"Gingrich";"Obama";"Romney"};C1)

But separating the search terms with semicolons doesn't apply the OR-condition correctly, so this is not the solution.

I'm aware from this answer that I could make separate searches and string them together with a condition, but I would like to avoid that, and I also want to know why the syntax that is supposed to work as confirmed by multiple sources is not working for me.

EDIT:

Okay, I'm starting to understand this, thanks to Solar Mike:

The code =IF(COUNT(SEARCH({"Romney","Obama","Gingrich"},A1)),1,"") works indeed perfectly fine.

Also =COUNT(SEARCH({"Romney","Obama","Gingrich"},A1)) works.

But =SEARCH({"Romney","Obama","Gingrich"},A1) does not.

Also =ISNUMBER(SEARCH({"Gingrich","Obama","Romney"},A1)) does not work.

I'd love to know the reason why.

Ok, so this works:

OR(IFERROR(FIND("ab",A1,1),0),IFERROR(FIND("12",A1,1),0))

tested here : 在此输入图像描述

I followed one of the links and the version like this:

=IF(COUNT(SEARCH({"Romney","Obama","Gingrich"},C1)),1,"")

worked as expected for me, but if the search is isolated it then fails and I have not found an explanation ...

Like other array-style formulas, the part that delivers the array has to be enclosed in some sort of aggregate function to make it scan through the array - otherwise it only looks at the first element of the array. So anything like COUNT, SUM, SUMPRODUCT will do the trick.

My preferred one is

=OR(ISNUMBER(SEARCH({"a","b","c"},A1)))

because you can easily change it to this if you want AND logic:

=AND(ISNUMBER(SEARCH({"a","b","c"},A1)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM