SubTotals Method - TotalList

  • Thread starter Thread starter jacqui
  • Start date Start date
J

jacqui

Nikos thanks for your earlier reply and example using
muliple fields in the TotalList:=Array(7,8,10,11) etc
What I should have explained is that I have 70 fields to
sum across my datafile so I need a more efficient way of
coding it, rather than listing each.
I do have variables holding firstcol and lastcol number so
is it correct to say TotalList:=Array(firstcol, lastcol)
or will this only sum the first column and last column
only.
Thanks
Jacqui
 
Jacqui,

Pls reply within the thread rather than starting a new one, it makes things
easier for everyone.

Now, to your question: you almost got me there! I had never tried this
before, and I admitt it puzzled me for a while. Anyway, I got it to work
with the following piece of code (column range and subtotals area are, of
course, hardcoded here for the sake of the example):

Sub Insert_Subtotals()
Dim arr() As Integer
firstcol = 2
lastcol = 5
ReDim arr(firstcol To lastcol)
For i = firstcol To lastcol
arr(i) = i
Next
ColArray = arr()
Range("A1:E13").Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, _
totalList:=ColArray, _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
End Sub

HTH,
Nikos
 
Back
Top