Solved

passing array in subtotal

Posted on 2011-03-16
4
318 Views
Last Modified: 2012-05-11
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
Comment
Question by:Ruchi_Sas
  • 2
4 Comments
 

Author Comment

by:Ruchi_Sas
ID: 35147135
does any one has answer to this question? If yes, then please answer
0
 
LVL 39

Accepted Solution

by:
nutsch earned 125 total points
ID: 35152833
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
 
LVL 39

Expert Comment

by:nutsch
ID: 35152839
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Macro 3 20
+1 to an even value 4 15
How to calculate time in/out/paused, resumed? 4 30
excel time calculation 11 22
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This collection of functions covers all the normal rounding methods of just about any numeric value.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now