[英]excel sum all cells where another cell contains a string
Example Table: 示例表:
| A | B -------------------------- 1 | 26 | tom, jerry -------------------------- 2 | 12 | tom -------------------------- 3 | 6 | jerry, tom, dick
Suppose I have this table. 假设我有这张桌子。 What I am trying to do is to sum up the total of cells in column A where the cell of the same row in column B contains a certain name, for example "tom". 我想做的是汇总A列中的所有单元格,其中B列中同一行的单元格包含某个名称,例如“ tom”。 However, before the cell in column A is added to the total, it has to be divided by the number of names in column B. 但是,在将A列中的单元格添加到总数之前,必须将其除以B列中的名称数。
So for example, if I used the name jerry, I would get a total of: 因此,例如,如果我使用名称jerry,我将得到总计:
(26/2) + (6/3) = 15 (26/2)+(6/3)= 15
If I used the name tom, I would get a total of: 如果使用汤姆这个名字,我将得到总计:
(26/2) + 12 + (6/3) = 27 (26/2)+ 12 +(6/3)= 27
Please help! 请帮忙! I am thinking that perhaps it might be too complex and I might need to split it up. 我认为这可能太复杂了,可能需要拆分。
Assuming that the name is in cell C1, this formula will do the job: 假设名称在单元格C1中,则此公式将完成以下工作:
=SUM($A$1:$A$3*NOT(ISERROR(SEARCH(C1,$B$1:$B$3)))/(LEN($B$1:$B$3)-LEN(SUBSTITUTE($B$1:$B$3,",",""))+1))
You need to enter it as an array formula, ie press Ctrl - Shift - Enter . 您需要将其作为数组公式输入,即按Ctrl - Shift - Enter 。
List the names in D2 down and then in E2 put this formula and copy down 在D2中列出名称,然后在E2中列出此公式并复制下来
=IF(D2="","",SUMPRODUCT(A2:A10,ISNUMBER(SEARCH(D2,$B$2:$B$10))/(LEN($B$2:$B$10)-LEN(SUBSTITUTE($B$2:$B$10,",",""))+1)))
That assumes that all names in B2:B10 are separated by commas, so you can get a count of the names in each cell by adding 1 to the number of commas 假定B2:B10中的所有名称都用逗号分隔,因此您可以通过在逗号数上加1来获得每个单元格中名称的计数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.