SubTotals method

J

jacqui

Can anyone help with the following VBA syntax. I have
created subtotals manually in Excel but would now like to
mimic this using VBA.
The first sweep of subtotals is based on field 5, so the
corresponding syntax is I guess groupBy:=5
The second sweep of subtotals is based on field 2. When I
did this manually I unchecked the Replace Current SubTotals

The question is how do I code recreate this in VBA using
two sweeps of SubTotals and how do I apply xlSum across
all fields. In the XL help example it says
totalList:=Array(2,3) based on fields 2 and 3 only. I'd
like a sub total for each.
Can anyone help?
Note a very helpful programmer has suggested using Pivot
Table instead and is going to reply to me on that one but
I would also like to learn the subtotal method as well.
Many thanks
Jacqui
 
N

Nikos Yannacopoulos

Jacqui,

Here's a working example of three level subtotals on multiple fields:

Selection.Subtotal GroupBy:=6, Function:=xlSum, TotalList:=Array(7, 8,
10, _
11, 13), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(7, 8,
10, _
11, 13), Replace:=False, PageBreaks:=False, SummaryBelowData:=True
Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(7, 8,
10, _
11, 13), Replace:=False, PageBreaks:=False, SummaryBelowData:=True

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top