Sumifs for multiple headers

Pete3p0

New Member
Joined
Jul 6, 2018
Messages
3
ABCDEFG
1SalesAmount SoldJohnPaulAdam
2JohnApples
3Apples5Oranges
4Oranges6Pears
5Pears4
6
7Paul
8Apples3
9Oranges8
10Pears5
11
12Adam
13Apples5
14Oranges8
15Pears7

<tbody>
</tbody>

Hey guys,

I have a whole bunch of sales data. I'd like to consolidate it into the table on the right (D1:G4). In cell E2, I tried putting in this formula:

=SUMIFS($B:$B,$A:$A,$D2,$A:$A,E$1)

but it keeps returning a 0

Thanks in advance.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the MrExcel board!

Hmm, I wonder how representative your data is?
If each person is only listed once in column A (like your sample) and each person has the same number of categories in the same order as each other (like your sample) then you could copy this formula across and down.

Excel Workbook
ABCDEFG
1SalesAmount SoldJohnPaulAdam
2JohnApples535
3Apples5Oranges688
4Oranges6Pears457
5Pears4
6
7Paul
8Apples3
9Oranges8
10Pears5
11
12Adam
13Apples5
14Oranges8
15Pears7
Table
 
Last edited:
Upvote 0
Hi Peter,

No the order can change and there might be different items under each name.

Table


ABCDEFG
1
Sales
Amount Sold
JohnPaulAdam
2
John


Apples
3Apples
5
Oranges
4Oranges6
Figs
5Bananas
4
Mangoes


6Watermelon
3
Pears



7
Watermelon
8
Paul






9
Apples3





10
Oranges8





11
Pears
5





12







13
Adam






14
Apples5





15
Oranges8





16
Mangoes
7





17
Figs
2
18

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:68px;"><col style="width:95px;"><col style="width:26px;"><col style="width:68px;"><col style="width:46px;"><col style="width:45px;"><col style="width:53px;"></colgroup><tbody>
</tbody>
 
Upvote 0
1. Does a name only ever appear once in column A or could John, for example, appear again for a second (or third, fourth etc) time further down the column?

2. Is there always a blank row before the next name like in both your sets of sample data?

3. If it turns out that a macro solution would be simplest, would that be acceptable to you?
 
Upvote 0
1. The names are all unique. IE John will only appear once
2. The blank row in this case will contain a total IE John's TOTAL --- 17
3. Perfectly acceptable.
 
Upvote 0
2. The blank row in this case will contain a total IE John's TOTAL --- 17
If that means the layout is as shown below, then you could try this user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy across & down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Code:
Function Tot(rData As Range, sName As String, sFruit As String) As Double
  Static d As Object
  Dim a As Variant
  Dim i As Long
  Dim s As String
  
  If d Is Nothing Then
    Set d = CreateObject("Scripting.Dictionary")
    d.CompareMode = 1
  End If
  a = rData.Value
  For i = 1 To UBound(a)
    If IsEmpty(a(i, 2)) Then
      s = a(i, 1)
    Else
      d(s & "|" & a(i, 1)) = a(i, 2)
    End If
  Next i
  Tot = d(sName & "|" & sFruit)
End Function

I presumed it was just an oversight that bananas was missing from your column D so I added it at the end.

Excel Workbook
ABCDEFG
1SalesAmount SoldJohnPaulAdam
2JohnApples535
3Apples5Oranges688
4Oranges6Figs002
5Bananas4Mangoes007
6Watermelon3Pears050
718Watermelon300
8PaulBananas400
9Apples3
10Oranges8
11Pears5
1216
13Adam
14Apples5
15Oranges8
16Mangoes7
17Figs2
1822
Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

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