Jack the Ripper
Jack the Ripper

Reputation: 25

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.

Upvotes: 2

Views: 202

Answers (2)

Dirk Reichel
Dirk Reichel

Reputation: 7979

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!

Upvotes: 3

Scott Craner
Scott Craner

Reputation: 152450

Use this formula:

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

enter image description here

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

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

enter image description here

Upvotes: 6

Related Questions