SUM(SUMIF(*{ formula

JohnnyTightlips

Board Regular
Joined
Aug 13, 2006
Messages
94
Hi Folks

In another thread in this forum I discovered the useful way to SUMIF multiple criteria in the same column e.g:

=sum(sumif(a1:a5,{"apples","oranges"},b1:b5 ))

Playing around with it, I have noticed that you need to explicitly state the criteria, as using a cell reference: e.g. C2 instead of "apples" produces an error.

Is there a way to reference cells? I am familiar with the curly braces as part of array formulas, but not with how they are applied in this type of formula; I assume it's a lack of understanding with what the formula is doing.

Otherwise, this an excellent forum; a shame I only stumbled on it recently
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi

Assuming that you have your apples and oranges in the range A7:A8, then try this array entered (ctrl, shift, enter)

Code:
=SUM(SUMIF(A1:A5,A7:A8,B1:B5 ))


Tony
 
Upvote 0
Try:

=SUM(IF(ISNUMBER(MATCH(A1:A5,C1:C2,0)),B1:B5))

Which must be confirmed with Control + Shift + Enter

Where C1 contains "Apples"
and C2 contains "Oranges"
 
Upvote 0
hi - welcome to the board!

consider the following:
Book1
ABCDEF
1apples17apples
2oranges37oranges
3oranges3
4melons4
5pears5
6
7
Sheet1


...the { } indicate an array. in:

=SUM(SUMIF(A1:A5,{"apples","oranges"},B1:B5 ))

...it's an array constant - the text string "apples","oranges". in:

=SUM(SUMIF(A1:A5,F1:F2,B1:B5 ))

...it's an array formula. you don't enter them directly in the latter case - formula gets entered with control + shift + enter + excel adds the { }.

review excel help file for 'About array formulas and array constants'
 
Upvote 0
I think there is no need to refer only to cells

try this formula

=SUMPRODUCT((A1:A5="apples")*(B1:B5))+SUMPRODUCT((A1:A5="oranges")*(B1:B5))
 
Upvote 0
Thanks to all for the quick replies.

The various solutions appear to require a contiguous range. Can I refer to non-contiguous cells? e.g. A2 & D4

Or am I just being difficult?! :wink:
 
Upvote 0
Thanks to all for the quick replies.

The various solutions appear to require a contiguous range. Can I refer to non-contiguous cells? e.g. A2 & D4

Or am I just being difficult?! :wink:
Hi Johnny:

Welcome to MrExcel Board!

Following is my convoluted formula that should work for you ...

=SUMPRODUCT(((ISNUMBER(MATCH(A1:A5,A2,0)))+(ISNUMBER(MATCH(A1:A5,D4,0)))),B1:B5)
 
Upvote 0
Hi Johnny:

Using A2, and D4 as ranges ... here is another convoluted formula of mine ...

=SUMPRODUCT((COUNTIF(INDIRECT({"a2","d4"}),A1:A5))*(B1:B5)+(ROW(1:5)=0))

Let me know how it goes!
 
Upvote 0
Thanks to all for their help

I realise my "problem" as such could be easily solved using multiple SUMIFS or SUMPRODUCTS (my favourite formula!)

I was just attracted to the elegant simplicity of the array constant (thanks Paddy) SUMIF formula: if it could refer to relative (non-contig.) cell references it would be my new fave formula

Oh well, at least I have a new favourite excel forum :LOL:
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top