Subtotalling multiple data groups

redjay

New Member
Joined
May 9, 2008
Messages
46
Hi Guys<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Wonder if any of you are able to help with this one. I have attached a JPG of what I have in mind.<o:p></o:p>
<o:p></o:p>
I have a simple sales worksheet showing Customer Name in Column A, Date of sale in Column B and Quantity in Column C. The data is sorted in that order.<o:p></o:p>
<o:p> </o:p>
I want some way of subtotalling the quantities by Name and Date. In other words, I want to be able to see how much each customer ordered on each date and for that value to be returned in Column D. Hopefully the attached image will make it clearer.

hrk27o.jpg
<o:p></o:p>

<o:p> </o:p>
I don’t think the Excel subtotals function would work for this and I don’t wish to use filters or pivot tables as I need all the data visible at the same time. Ideally I would like some code or a formula (or indeed an Excel function im not aware of!).<o:p></o:p>
<o:p> </o:p>
Many thanks <o:p></o:p>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG09May21
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] tot [COLOR="Navy"]As[/COLOR] Double
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & rows.Count).End(xlUp))
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
        tot = tot + Dn.Offset(, 2)
            [COLOR="Navy"]If[/COLOR] Not Dn & Dn(, 2) = Dn(2) & Dn(2, 2) [COLOR="Navy"]Then[/COLOR]
                Dn(, 4) = tot
                tot = 0
            [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
My fault, change the Line below, the code is trying to read you headers as a number !!!
Rich (BB code):
Set Rng = Range(Range("A2"), Range("A" & rows.Count).End(xlUp))
Regards Mick
 
Upvote 0
hi,

A formula solution that might work in D2 and copied down...

=IF(B2=B3,"",SUMPRODUCT(--($A$2:$A$23=A2),--($B$2:$B$23=B2),$C$2:$C$23))


Excel Workbook
ABCD
1NameDateQuantityTotal
2Jones01/01/20102*
3Jones01/01/20102*
4Jones01/01/201026
5Jones01/08/20113*
6Jones01/08/201136
7Smith01/01/20102*
8Smith01/01/20102*
9Smith01/01/201026
10Smith13/08/20103*
11Smith13/08/20103*
12Smith13/08/20103*
13Smith13/08/20103*
14Smith13/08/2010315
15Andrew14/05/20102*
16Andrew14/05/20102*
17Andrew14/05/201026
18Andrew03/06/20103*
19Andrew03/06/20103*
20Andrew03/06/201039
21Andrew05/05/20114*
22Andrew05/05/20114*
23Andrew05/05/2011412
Sheet4



Oops! Too late.

Ak
 
Upvote 0
Be careful with the sumproduct formula, it only works if column a is sorted, if names are not sorted this formula works incorrectly.

The Macro will work perfect.

I would not use this formula, you could have spreadsheet sorted by date, then the formula does not work.
 
Upvote 0
Hi jrabi,

Does this seem better?


Excel Workbook
ABCDE
1NameDateQuantity*Total
2Jones01/01/20102**
3Jones01/01/20102**
4Jones01/01/20102*6
5Jones13/08/20103**
6Jones13/08/20103**
7Smith13/08/20103**
8Smith13/08/20103**
9Smith13/08/20103*9
10Smith01/01/20102**
11Smith01/01/20102**
12Smith01/01/20102*6
13Smith01/08/20113**
14Smith01/08/20113*6
15Andrew14/05/20102**
16Andrew14/05/20102**
17Andrew14/05/20102*6
18Andrew03/06/20103**
19Andrew03/06/20103**
20Andrew03/06/20103*9
21Andrew05/05/20114**
22Andrew05/05/20114**
23Andrew05/05/20114*12
Sheet1


Or this....

Excel Workbook
ABCDE
1NameDateQuantityTotal
2Jones01/01/20102 
3Jones01/01/20102
4Jones01/01/20102
5Smith01/01/20102
6Smith01/01/20102
7Smith01/01/201026
8Andrew14/05/20102
9Andrew14/05/20102
10Andrew14/05/201026
11Andrew03/06/20103
12Andrew03/06/20103
13Andrew03/06/201039
14Jones13/08/20103
15Jones13/08/20103
16Smith13/08/20103
17Smith13/08/20103
18Smith13/08/201039
19Andrew05/05/20114
20Andrew05/05/20114
21Andrew05/05/2011412
22Smith01/08/20113
23Smith01/08/201136
Sheet1





Ak
 
Last edited:
Upvote 0
Not sure if it seems better, but your formula is flawed, I would not use...

This solution would require an array formula to look at both columns...
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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