J
jday
I have a worksheet range containing attributes in columns A, B, and C -- with
data to be subtotaled in column D. The attribute columns are sorted so they
are grouped together appropriately left to right. I want to insert subtotals
both at column A and B -- with a being the primary group, and subtotals for
column B nested inside that. I also want, in both cases, for the actual
subtotal row to be ABOVE each grouping vs. below. Here is the code I am
using:
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=False
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(4), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=False
The problem happens when it creates/inserts the subtotals for the 2nd
iteration in column B. In each case, the first 'subtotal' row for column B
appears ABOVE the subtotal row in column A, and in some cases, the last
subtotal row for column B is duplicated with both a subotal at the top &
bottom. If I edit the code to allow the summary data to fall BELOW the
group, it summarizes everything correctly. In other words, it is my attempt
to keep each summary at the top of each group that seems to be causing my
issue---but this is what I REALLY want. By the way, I cannot use a pivot
table due to other things I will be doing with this data. Any suggestions on
what I can do -- or is there something wrong with my code that I am missing?
data to be subtotaled in column D. The attribute columns are sorted so they
are grouped together appropriately left to right. I want to insert subtotals
both at column A and B -- with a being the primary group, and subtotals for
column B nested inside that. I also want, in both cases, for the actual
subtotal row to be ABOVE each grouping vs. below. Here is the code I am
using:
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=False
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(4), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=False
The problem happens when it creates/inserts the subtotals for the 2nd
iteration in column B. In each case, the first 'subtotal' row for column B
appears ABOVE the subtotal row in column A, and in some cases, the last
subtotal row for column B is duplicated with both a subotal at the top &
bottom. If I edit the code to allow the summary data to fall BELOW the
group, it summarizes everything correctly. In other words, it is my attempt
to keep each summary at the top of each group that seems to be causing my
issue---but this is what I REALLY want. By the way, I cannot use a pivot
table due to other things I will be doing with this data. Any suggestions on
what I can do -- or is there something wrong with my code that I am missing?