[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

passing array in subtotal

I need to pass array in subtotal
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array( 1 to lastcolumn ), _
                Replace:=True, PageBreaks:=False, SummaryBelowData:=True

I am doing the above fn. Please help and let me know how to pass 1 to lastcoulmn in this array
0
Ruchi_Sas
Asked:
Ruchi_Sas
  • 2
1 Solution
 
Ruchi_SasAuthor Commented:
does any one has answer to this question? If yes, then please answer
0
 
nutschCommented:
You can do something like this. Probably not the most efficient, but it should do.

Dim arrSeries(), lgMin As Long, lgMax As Long

lgMin = 2
lgMax = 6

ReDim Preserve arrSeries(lgMax - lgMin)

For i = lgMin To lgMax
    arrSeries(i - lgMin) = i
Next

Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=arrSeries, Replace:=True, PageBreaks:=False, SummaryBelowData:=True

Open in new window


Thomas
0
 
nutschCommented:
something like this with the last column (you can't put the first column since you're grouping on it)

Sub Macro3()
'
' Macro3 Macro
Dim arrSeries(), lgMin As Long, lgMax As Long

lgMin = 2
lgMax = Cells(1, Columns.Count).End(xlToLeft).Column

ReDim Preserve arrSeries(lgMax - lgMin)

For i = lgMin To lgMax
    arrSeries(i - lgMin) = i
Next

Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=arrSeries, Replace:=True, PageBreaks:=False, SummaryBelowData:=True

End Sub

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now