Subtotal function

A

Austin

I have some VBA code that should subtotal a table based on the 1st column and
then resubtotal on the second column. The problem I am having is that the
second subtotal puts the "Section Total" label in the first column as well.
Any ideas on what I am doing wrong? Thanks for the help:

ColStart = 2
ColEnd = lvlColumn + 2

ReDim Columns(0 To (ColEnd - ColStart))
For i = ColStart To ColEnd
Columns(i - ColStart) = i
Next i

ColSt = 2
ColEn = lvlColumn + 2

ReDim Columns2(0 To (ColEn - ColSt))
For n = ColSt To ColEn
Columns2(n - ColSt) = n
Next n

With xlSheet.Range("A:ZZ")
.Cells.Copy
.Cells.PasteSpecial (xlPasteValues)
.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Columns, _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Columns2, _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True
End With
 
J

John Bundy

Your column and column2 values are the same:
ColStart = 2
ColEnd = lvlColumn + 2

ColSt = 2
ColEn = lvlColumn + 2

i think for what you are describing (subtotal by column b, then c) you need

ColSt = 3
ColEn = lvlColumn + 3
 
A

Austin

Perfect, thanks a lot

John Bundy said:
Your column and column2 values are the same:
ColStart = 2
ColEnd = lvlColumn + 2

ColSt = 2
ColEn = lvlColumn + 2

i think for what you are describing (subtotal by column b, then c) you need

ColSt = 3
ColEn = lvlColumn + 3
 

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

Top