简体   繁体   中英

Excel Formula INDEX MATCH multiple search criteria

I'm trying to find a way to do an INDEX MATCH on multiple criteria but I am not having much luck.

I have 3 text entries that I want to flag the "Harmful" tag, which are " c001 "," c002 " and " c003 ".. they will likely not be in a sorted list.

=IFERROR(IF(INDEX(F9:F34,MATCH("*C001*",$B$9:$B$34,0)),"Harmful",""),"")

Now this above works perfectly but every combination with nested IF statements and IF(OR formulae don't work for me!

Note that I am using wildcards because these codes are likely to form part of a longer text string.

Any advice/guidance will be greatly appreciated.

Kind Regards.

If you did want to do it in one formula, try this one:-

=IF(SUMPRODUCT(ISNUMBER(FIND({"C001","C002","C003"},B9:B34))*ISNUMBER(F9:F34)),"Harmful","")

Actually this doesn't quite do the same as OP's INDEX/MATCH because a zero in F9:F34 in the above formula would give ISNUMBER=TRUE and could flag it as harmful while a zero in the original formula wouldn't.

Alternative:-

=IF(SUMPRODUCT(ISNUMBER(FIND({"C001","C002","C003"},B9:B34))*N(+F9:F34)),"Harmful","")

I was going to add that the reason nested IF's and OR's don't work with OP's formula is that when the match fails for the first time the formula's execution goes straight to the empty string "" in the IFERROR statement so it doesn't evaluate any other conditions. You'd have to separate them something like this:-

=IF(IFERROR(INDEX(F9:F34,MATCH("*C001*",$B$9:$B$34,0)),0)+IFERROR(INDEX(F9:F34,MATCH("*C002*",$B$9:$B$34,0)),0)+IFERROR(INDEX(F9:F34,MATCH("*C003*",$B$9:$B$34,0)),0),"Harmful","")

Is there a particular reason it needs to be in the form of an INDEX function, or need to all be done in one column? (If it is, I'll hazard a guess in your formula you want the INDEX function to be looking at the same column B that's in your MATCH function?... maybe one reason it's not working?)

A simpler solution imho would be to add some new columns next to your list, which check for the existence of each of your search strings, and record a flag of 1, which asserts existence. The FIND function is probably what you're after, which returns an error if it cannot find the reference string.

ie

in cell H9 =IF(ISERROR(FIND("C001",F$9)),1,0)

in cell I9 =IF(ISERROR(FIND("C002",F$9)),1,0)

... etc

Then at the end of these check columns, sum up the values. You will then know if the sum is greater than zero then at least on of your bad strings has been found, and that is a harmful value to flag.

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