简体   繁体   English

excel对另一个单元格包含字符串的所有单元格求和

[英]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.

相关问题 Excel sum函数,其中某些单元格为字符串 - Excel sum function where some cells are string 包含字符串的EXCEL SUM单元格 - EXCEL SUM cells which contain string Excel:如果单元格共享相同的未知字符串,则求和 - Excel: Sum cells if they share an identical unknown string excel:如果包含文本字符串,如何返回整个单元格 - excel : how to return the entire cell if it contains a text string Excel宏选择包含字符串的单元格并替换字符 - Excel macro select cell that contains a string and replace a character 查找包含另一个字符串中字符串的所有字符的最小窗口的长度 - Find length of smallest window that contains all the characters of a string in another string 检查一个字符串是否以相同的顺序包含另一个字符串的所有单词python? - Check if a string contains all words of another string in the same order python? 测试字符串是否包含构成另一个字符串的所有字符 - Test If String Contains All Characters That Make Up Another String function 检查一个字符串是否包含另一个字符串的所有元素 - function to check if a string contains all elements of another string java - 检查一个字符串是否包含另一个字符串的所有字符,但顺序不对 - java - check If a String contains all characters of another String, but not in order
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM