SUMIF multiple columns

joe-carter

New Member
Joined
Jul 2, 2004
Messages
34
I'm trying to sumif for a range. Pretend below is an exceil file with A1=1, and D4=A. I wrote "=SUMIF(D1:D4,"A",A1:C4)". The answer would be "7", or 1+2+2 in the first "A" row plus 1+0+1 in the second "A" row. It worked for a while, but now it won't. The problem is A1:C4, it seems the SUMIF command wants this to be A1:A4. I could make a big sumif command "=SUMIF(D1:D4,"A",A1:A4)+SUMIF(D1:D4,"A",B1:B4)+SUMIF(D1:D4,"A",C1:C4)", but would rather be clever.

1, 2, 2, A
2, 2, 1, B
1, 1, 1, C
1, 0, 1, A

Thanks,

Joe
 
Try this

Formula in B10 copied down
=SUMIF($B$1:$E$1,$B$9,INDEX($B$2:$E$6,MATCH($A10,$A$2:$A$6,0),0))

M.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Yes, thank you. I thought it was going to be an Index/Match. I for the life of me cannot master the Index/Match, I get the vlookup and the hlookup, trouble with the Index/Match.
 
Upvote 0


I'm hoping this is the place for some help on a similar problem. I would like to sumif data from multiple columns but to build on this example where there are repeats in the rows (so column a could be a,b,c,a,a,d,e). Also rather than matching the column title I want to make the number of columns vary based on the current month (so include columns B:H if it is July or month 7 and include columns B:M if it is December or Month 12).

So the data may look like below.

I've tried a couple approaches to achieve this.

First I adapted the formula in this thread but realise the match will only return the first instance of "material 1"
=SUM(INDEX($B$2:$H$5,MATCH(A10,$A$2:$A$5,0),0))

Second I tried achieving this with a combination of offset and sumproduct. The formula I have though covers the full 12 months and I don't know how to adapt the index (without using indirect) to only sum months up until specified current month.
=SUMPRODUCT(($A$2:$A$5=$A10)*(OFFSET($B$2:$M$5,0,0,,)))

Greatly apprecaite any views.

<tbody>
</tbody>
s!AqJm0w3NgEWJjZlFDfJvnW_1TO4tPQ


ABCDEFGHIJKLM
1janfebmaraprmayjunjulaugsepoctnovdec
2Material 222116913123626
3Service55233153339
4Material 222116913123626
5Service 335302514689329
6
7
8
9Current Month7
10Material 2954
11Service
12Service 3

<tbody>
</tbody>


<tbody>
</tbody>
 
Upvote 0
Maybe this

B10 copied down
=SUMPRODUCT((COLUMN($B1:$M1)-COLUMN($B1)+1<=B$9)*(A$2:A$5=A10)*B$2:M$5)

M.
 
Upvote 0
Equally, in B10 control+shift+enter, not just enter, and copy down:

=SUM(IF($A$2:$A$5=$A10,OFFSET($B$2:$M$5,0,0,,B$9)))

A formula blank or text value would not affect this adversely.
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,009
Members
449,093
Latest member
ikke

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