简体   繁体   中英

Count or Sum (?) items in a single cell that match criteria from a list in Excel

I have a single cell that is the output of a survey, that contains items selected from a list of 20 possible items.

ie. Original possible selections:

Ape, Blue, Cat, Red, Dog, Yellow, Pig, Purple, Zebra

User is asked to "select all of the animals," from the list of possible selections. The output places all of the items they've identified into a single cell, separated by commas. A new row is created for each survey entry.

ie.

| User 1 | "Ape, Cat, Pig, Purple" |

| User 2 | "Cat, Red, Dog, Pig, Zebra" |

| User 3 | "Ape, Cat, Dog, Pig, Zebra" | etc...

I have a table with all of the animals and colors, with defined ranges.

ie. animals = A1:A5, and colours = B1:B4

I need to "score" the cell for each user, in a new cell. Where the score value is the count of the number of correctly identified items each counts as 1 point.

ie.

| User 1 | "Ape, Cat, Pig, Purple" | 3 |

| User 2 | "Cat, Red, Dog, Pig, Zebra" | 4 |

| User 3 | "Ape, Cat, Dog, Pig, Zebra" | 5 |

What would the formula need to be for that score cell for each row?

I found a previous thread, that seems to point in the right direction, Excel: Searching for multiple terms in a cell But this only checks for the existence of any of the items in a cell from a list and returns a true or false

Thanks for anyone's help!

COUNTIF with SUMPRODUCT:

=SUMPRODUCT(COUNTIF(D2,"*" & $A$1:$A$5 & "*"))

Which also has the limitation of the amimals not being a sub-string, like Ant and Ant-Eater

在此处输入图片说明


If sub-strings are a problem then use this:

=SUMPRODUCT(--(ISNUMBER(SEARCH(", " & $A$1:$A$5 & ", ",", " & D2 & ", "))))

This will make a complete match between the commas.

在此处输入图片说明

The formula shown is entered in D3 (an array formula, so use Ctrl + Shift + Enter ) and filled down to D5

A3:A6 is a named range "animals"

Note this is only reliable if none of your terms are sub-strings of another term.

在此处输入图片说明

If you do not like to use the formulas above, which are very efficient and most ideal, a simpler but longer way would be as follows:

select the animals--> Data--> Text to Columns, and split them into columns with the separator being a comma

Once this is done, do a countif on each column, and it will total it up for you. You will need to do 20 countifs though, so it is far from ideal IE

=countifs(column which it could be in],[no.1 animal])+
countifs(column which it could be in],[no.2 animal])+...
countifs(column which it could be in],[no.20 animal])

This is easy to see how it works and if you receive more answers you will have to split them out again

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