简体   繁体   中英

Excel - Sum of values in multiple columns

apple   banana  apple
 52       12     35
 25       21     53
 44       65     41

How do I get the sum of all values in multiple columns that satisfy a condition (say looking for columns having apple as the header) and I can get the sum of all the values appearing under apple column. I need 250 as the answer. Is it possible to generate it using formulas? In other words, I look for headers containing apple and provide total of all the numbers that fall within the header.

Thanks in advance.

Use this formula:

=SUM(INDEX((A1:C1=E2)*A2:C4,))

在此输入图像描述

As per your comments to find if the Word is in a longer string use:

=SUM(INDEX((ISNUMBER(SEARCH( E2,A1:C1)))*A2:C4,))

在此输入图像描述

Sumproduct will do:

=SUMPRODUCT(A2:C4*(A1:C1="apple"))

Going with Scotts layout for fruits including the keyword:

=SUMPRODUCT(A2:C4*ISNUMBER(SEARCH(E2,A1:C1)))
=SUMPRODUCT(A2:C4*ISNUMBER(FIND(E2,A1:C1)))

FIND if case matters and SEARCH if not.
For excluding the keyword (for being somewhere in the names) simply replace ISNUMBER with ISERROR

EDIT :

When dealing with non-numeric values (such as text or errors) you can use this array formula:

=SUM(IF(ISNUMBER(A2:C4),A2:C4)*ISNUMBER(SEARCH(E2,A1:C1)))

This is an array-formula and must be confirmed with ctrl + shift + enter !

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