[英]Excel: apply formula to each cell before SUM operation
I am trying to do a SUM on a range of cells but instead of using the value in the cell as IS I need to extract a piece from each cell to use in the sum. 我正在尝试对一定范围的单元格进行求和,但不是像IS那样使用单元格中的值,而是需要从每个单元格中提取一个片段以用于求和。 In the example below I need to use the value before the - sign. 在下面的示例中,我需要在-号之前使用该值。
A
1 1-3
2 2-60
3 5-3
4 =SUM(A1:A3)
SUM should be the addition of the first piece (before the -) so 1 + 2 + 5 SUM应该是第一部分的加法(在-之前),所以1 + 2 + 5
I found a way to extract the data by using 我找到了一种使用提取数据的方法
=LEFT(A1, SEARCH("-",A1,1)-1) = 1
=LEFT(A2, SEARCH("-",A2,1)-1) = 2
=LEFT(A3, SEARCH("-",A3,1)-1) = 5
But how can I SUM the value of these formulas without having to use any more additional cells? 但是,如何在不使用任何其他单元的情况下求和这些公式的值?
Use an array formula: =SUM(VALUE(LEFT(A1:A3, SEARCH(A1:A3, "-")-1)))
. 使用数组公式: =SUM(VALUE(LEFT(A1:A3, SEARCH(A1:A3, "-")-1)))
。 Then press Shift-Ctrl-Enter to tell Excel this is an array formula. 然后按Shift-Ctrl-Enter告诉Excel这是一个数组公式。
=SUMPRODUCT(--(LEFT(A1:A3,FIND(A1:A3,"-")-1)))
This is a none CSE formula that peforms array like operations. 这是一个无CSE公式,可以执行类似数组的操作。 As such you should avoid full column references within the sumproduct. 因此,应避免在sumproduct中使用完整的列引用。 Also note, things may go a little "WONKY" if there is no - in the cell. 另请注意,如果单元格中没有-东西可能会有点“ WONKY”。 To avoid that you could add a - to the very end. 为了避免这种情况,您可以在最后添加-。 Formula would look something like this: 公式如下所示:
=SUMPRODUCT(--(LEFT(A1:A3&"-",FIND(A1:A3&"-","-")-1)))
That will work when you just have integers and no formula 当您只有整数而没有公式时,它将起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.