Can someone help me with this? Probably a beginner level formula.

Python49

New Member
Joined
Aug 18, 2018
Messages
32
I want to do SUMIFs for the following image but for more than one flavor criterion. The two flavors highlighted in yellow both have the same date and location, so I'd like to be able to get the total for them both without just simply typing another +SUMIFS formula for the second flavor. Mainly because the list of flavors can be very long, so therefore the formula would become
open
too long. I've toyed around with some SUMPRODUCT formulas but can't get one to sum multiple flavors with multiple qualifiers.

open
open
https://drive.google.com/open?id=13yEfHm5cbggEuCAjffk4UjVm4tonCB-4
 
If you want to progress with this can you post the exact formula you ended up using and a small set of sample data that demonstrates the problem.



This sounds like a good way forward to me, especially if you don't get on well with the pivot tables.
ABCDEFG
FlavorDateLocationTotalDate LocationFlavor
Oreos8/2/2019USA10009/5/2019USAOreos
Vanilla9/5/2019USA1000Vanilla
Chocolate9/5/2019USA1000Chocolate

<tbody>
</tbody>

I tried: =SUMPRODUCT(SUMIFS(D:D,B:B,E2,C:C,F2,A:A,G2:G8)) --- This gives me 0
=SUMPRODUCT(SUMIFS(D:D,B:B,E2,C:C,F2,A:A,G2)) --- This gives me 1000 for Oreos total.
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
or you can go with a VBA solution where i think as long as all 31 sheets are the same it would be useful.
do you have a master list of flavors on a separate sheet by chance?
Yes, I've got a master list that's used with all the flavors and other details on a table which I use to index some data from on the 31 other sheets. I'm going to add the flavor groups to that and then index it on the 31 sheets so I can get the SUMIFS.
 
Upvote 0
I can highly recommend the Book powerbi and powerpivot by Rob collie and Avichal Singh. It is really really good and it gave me alot of new skills. Learn this Book and you Will set yourself far above the "Excel champ" label.
 
Upvote 0
I tried: =SUMPRODUCT(SUMIFS(D:D,B:B,E2,C:C,F2,A:A,G2:G8)) --- This gives me 0

That exact formula, with that exact sample data returns 2000 (as expected) for me :confused: .


Excel 2013/2016
ABCDEFGHI
1FlavorDateLocationTotalDateLocationFlavor2000
2Oreos08/02/2019USA100009/05/2019USAOreos
3Vanilla09/05/2019USA1000Vanilla
4Chocolate09/05/2019USA1000Chocolate
Sheet1
Cell Formulas
RangeFormula
I1=SUMPRODUCT(SUMIFS(D:D,B:B,E2,C:C,F2,A:A,G2:G8))
 
Last edited:
Upvote 0
Yes, I've got a master list that's used with all the flavors and other details on a table which I use to index some data from on the 31 other sheets. I'm going to add the flavor groups to that and then index it on the 31 sheets so I can get the SUMIFS.

here is my VBA solution

try this:
1. Make a userform with two listboxes (ListBox1 and ListBox2) and a command button (CommandButton1)
2. Make sure ListBoxes have multi select enabled (set the MultiSelect option in the properies panel to 2)
3. open the userform's code via right click > view code
4. copy and paste the code below
6. Add a module to your VBA project and copy/paste the flAVA code
5. run macro "flAVA"

notes:
- This rough draft does not include date specificity. if you want to specify a date just confirm that this is what you're looking for and we'll adjust accordingly.
- Make sure your flavors are in column A of a sheet named "Master List" or change both the sheet name and the column ranges of userform_activate to the respective column/sheet flavors are held in
- Make sure your Locations are in column B of a sheet named "Master List" or change both the sheet name and the column of 'lastRow' to the respective column/sheet flavors are held in
- This will execute the code on every sheet except for Master List. You have not made anyone aware of any other sheets besides this and the 31 sheets. Add any additional sheets to the sheet exemption
- when selecting multiple flavors/locations in the listbox use ctrl + click
- the results will appear in columns D-F of "Master List". change as you see fit

see this workbook as an example
https://drive.google.com/file/d/1_e1zAI42Y-4p4sKkMrWBrpTV_rZ13_6W/view?usp=sharing

this goes into your UserForm1 code
Code:
Sub flavorTOWN()
Dim ws As Worksheet, os As Worksheet
Dim wsCOUNT As Long, lastRow As Long
Dim i As Long, x As Long, j As Long, p As Long
Dim flSELECT(), loSELECT(), sSheet As Variant
Dim sumFLAV As Variant
Dim dicLOCATION As Object, dicFLAVOR As Object

'set variables
Set os = Sheets("Master List")
lastRow = os.Range("A" & Rows.Count).End(xlUp).Row
Set dicLOCATION = CreateObject("scripting.dictionary")
Set dicFLAVOR = CreateObject("scripting.dictionary")

    x = 0
    'pass all selected flavors into array
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) = True Then
            ReDim Preserve flSELECT(x)
            flSELECT(x) = ListBox1.List(i)
            x = x + 1
        End If
    Next i
    
    x = 0
    'pass all selected locations into array
    For i = 0 To ListBox2.ListCount - 1
        If ListBox2.Selected(i) = True Then
            ReDim Preserve loSELECT(x)
            loSELECT(x) = ListBox2.List(i)
            x = x + 1
        End If
    Next i

    'size of the sums array
    ReDim sumFLAV(LBound(flSELECT) To UBound(flSELECT), LBound(loSELECT) To UBound(loSELECT))

    'use arrays to get sums
    For Each ws In Sheets
        If ws.Name <> "Master List" Then
        'or ws.name <>"OTHERSHEETS" then
            sSheet = ws.Range("A1").CurrentRegion.Value2
            
            For i = LBound(sSheet) To UBound(sSheet)
        For x = LBound(loSELECT) To UBound(loSELECT)
            If sSheet(i, 3) = loSELECT(x) Then
                For p = LBound(flSELECT) To UBound(flSELECT)
                    If sSheet(i, 1) = flSELECT(p) Then
                     sumFLAV(p, x) = sumFLAV(p, x) + sSheet(i, 4)
                    End If
                Next p
            End If
        Next x
    Next i
            
        End If
    Next ws
            

    'paste results to sheet
    x = 2
    For j = LBound(loSELECT) To UBound(loSELECT)
        os.Range("D" & x).Value = loSELECT(j)
            For p = LBound(flSELECT) To UBound(flSELECT)
                os.Range("E" & x).Value = flSELECT(p)
                os.Range("F" & x).Value = sumFLAV(p, j)
                x = x + 1
            Next p
    Next j
        


            
            



End Sub

Private Sub UserForm_Activate()
Dim ws As Worksheet
Dim flARY As Variant, loARY As Variant

Set ws = Sheets("Master List")
lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
flARY = ws.Range("A2:A" & lastRow).Value2
loARY = ws.Range("B2:B" & lastRow).Value2

ListBox1.List = flARY
ListBox2.List = loARY
End Sub

Private Sub CommandButton1_Click()
Call flavorTOWN
Unload UserForm1
End Sub

this goes into a module or just use .show in any method of opening the userform
Code:
Sub flAVA()
UserForm1.Show
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

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