Summing numeric portion of cell when alpha portion of cell is the same

折月煮酒 提交于 2019-12-11 13:59:54

问题


I have a spreadsheet that has columns for dates and the values can be either "1v, .5v, 1p, .5p, 1s, .5s" I have 3 columns in each row one for each letter "v, p and s". I want to be able to add the total of all cells in the range grouped by letter and then display the sum for each letter in it's respective column (v, p or c).

Here is an example of the sheet:

Name     Vacation   Personal   Sick   1/5/15  1/6/15  1/7/15  1/8/15
Billy       1.5        1         0       .5v    1v              1p

It is the formula that goes in the vacation/personal/sick cell that I just can't figure out.


回答1:


I went down the array formula route and came up with essentially the same formula as @Sancho.s :-

=SUM(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"))

You could modify it to take account of blanks:-

=SUM(IF($E2:$H2<>"",LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v")))

Perhaps this would be better, to ignore any mis-formatted cells:-

=SUM(IFERROR(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"),0))

These all have to be put in with Ctrl-Shift-Enter.




回答2:


Assuming the range you posted starts at A1, use

=SUMPRODUCT((RIGHT($E2:$G2,1)="v")*LEFT($E2:$G2,LEN($E2:$G2)-1))

in B2. Change "v" and the range to use suitably.

Pro:

  • It is not an array formula. See why this may be important

Con:

  • I could not make it work with blank cells.



回答3:


This "array entered" version will also allow blanks

=SUM(IF(RIGHT(E2:G2)="v",SUBSTITUTE(E2:G2,"v","")+0))

confirmed with CTRL+SHIFT+ENTER



来源:https://stackoverflow.com/questions/27784048/summing-numeric-portion-of-cell-when-alpha-portion-of-cell-is-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!