简体   繁体   中英

excel formula to add cells in a single row based on criteria

Let's say,

Sheet1:A1 = x

Sheet2 contents look like

x 3 3 4 
y 0 2 1

Is there an excel formula that could match Sheet1:A1 with Sheet2:A1 (basically the value 'x') and add the other cells in that row (3,3,4). The result (Sum='10') should get updated at Sheet1:C4 lets say.

I tried SUMIF but that shows the content of only one column due to the restriction that it can handle only the matchable array size. I know this can be achieved through VBA, but just wanted to know if a formula is available.

TIA!

This formula will do what you want:

=SUM(SUMIF(Sheet2!A:A,A1,INDIRECT("Sheet2!" & {"B:B","C:C","D:D"})))

It will iterate through the columns doing individual SUMIF() on each and then adding the results.

If you want more columns or different change the address in the array to the columns desired.

在此处输入图片说明

Try the following

=SUM(IF(Sheet2!A1:A99=A1,Sheet2!B1:D99,0))

Note that this is an array formula, so it must be entered using Ctrl + Shift + Enter .

What this formula does is converts any rows on Sheet2 without x in column A to zeros in B:D and then sums what is left.

Similarly, you could use

=SUMPRODUCT((Sheet2!A1:A99=A1)*Sheet2!B1:D99)

and you wouldn't have to enter it as an array formula.

对于非易失性,非数组公式,请尝试以下操作

=SUM(INDEX(Sheet2!B:D,MATCH(Sheet1!A1,Sheet2!A:A,0),))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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