简体   繁体   English

在单个单元格中对与Excel中列表中的条件匹配的项目进行计数或求和(?)

[英]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. 我有一个单元格作为调查的输出,其中包含从20种可能的项目列表中选择的项目。

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 | 用户1 | "Ape, Cat, Pig, Purple" | “猿,猫,猪,紫色” |

| | User 2 | 用户2 | "Cat, Red, Dog, Pig, Zebra" | “猫,红色,狗,猪,斑马” |

| | User 3 | 用户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 动物= A1:A5,颜色= 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. 得分值是正确识别的项目数的计数,每个项目都计为1分。

ie. 即。

| | User 1 | 用户1 | "Ape, Cat, Pig, Purple" | “猿,猫,猪,紫色” | 3 | 3 |

| | User 2 | 用户2 | "Cat, Red, Dog, Pig, Zebra" | “猫,红色,狗,猪,斑马” | 4 | 4 |

| | User 3 | 用户3 | "Ape, Cat, Dog, Pig, Zebra" | “猿,猫,狗,猪,斑马” | 5 | 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 我找到了上一个线程,它似乎指向正确的方向, Excel:在单元格中搜索多个术语,但这仅检查列表中单元格中是否存在任何项目,并返回true或false

Thanks for anyone's help! 感谢任何人的帮助!

COUNTIF with SUMPRODUCT: COUNTIF与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 这也限制了动物不是子字符串,例如AntAnt-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 显示的公式在D3中输入(数组公式,因此请使用Ctrl + Shift + Enter )并向下填充至D5

A3:A6 is a named range "animals" A3:A6是一个命名范围“动物”

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 尽管您将需要执行20个计数,所以它远非理想的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 很容易看到它是如何工作的,如果您收到更多答案,则必须再次将它们分开

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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