简体   繁体   中英

Excel formula if any cell in a range has a value get the value of another cell

I have the following table

     A   B
1    3   Val1
2    2   Val2
3    2   Val3
4    1   Val1
5    5   Val3

Can anybody help me with a formula to sum cell values from the A column grouped by values of the B column

So it should return Val1 = 4 another formula for Val=2 another for Val3 =7

I Have the following but it is very ugly:

=IF(B1="Val1";A1)+IF(B2="Val1";A2)+IF(B3="Val1";A3)+IF(B4="Val1";A4)+IF(B5="Val1";A5)

您可以按以下方式使用SUMIF

=SUMIF(B:B;"Val1";A:A)

可以对每个Valx使用以下公式:

=SUMIF(B1:B5,"Val1",A1:A5)

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