Specify Columns to Subtotal

ijswalker

Registered User.
Local time
Today, 12:18
Joined
Jun 16, 2008
Messages
67
Hi

I have some code below that inserts a subtotal at the breaks I need. However. I can't seem to get it to be specific to the columns I want to subtotal. I have tried changing the numbers in
Code:
For I = 3 To FinalCol
with no luck.

I also want it to exclude the Grand Total row with no luck. I have tried
Code:
RowGrand:= False
in the last line of the code.

Can anyone help?

Thanks

Ian

Code:
Sub InsertSubtotals()
Dim TotColumns()
Dim I As Integer
FinalCol = Cells(3, 255).End(xlToLeft).Column
ReDim Preserve TotColumns(1 To FinalCol - 2)
For I = 3 To FinalCol
    TotColumns(I - 2) = I
Next I
Selection.Subtotal GroupBy:=5, Function:=xlSum, TotalList:=TotColumns, Replace:=True, PageBreaks:=True, Summary
 
how about uploading the workbook as a sample? it's hard to tell from just what you have here...
 
I've attached a sample of the workbook

Thanks

Ian
 

Attachments

Figured it out,

In order to subtotal the appropriate columns the numbers in the code need to be changed. The
Code:
For I = 8 To FinalCol [CODE] needs to be 1 more than numbers in the following lines. [CODE]TotColumns(1 To FinalCol - 7)
[CODE] and [CODE]TotColumns(I - 7) = I[CODE]
 
As you increment the numbers the subtotals will move along a column. The above code will subtotal from Column 8. 
 
Hope that makes sense.
 
Thanks
 
Ian
 

Users who are viewing this thread

Back
Top Bottom