Solved

How to create an Excel Groups and Subtotals

Posted on 2004-10-01
2
570 Views
Last Modified: 2008-01-09
Hi all,

From within:
With wkbApp
End with

I am trying to create an Excel report using the Tools, Subtotal options to create subtotals in three columns, grouping on one column using the following code. The code was recorded in the Excel macros and copied to VB.net -

.Selection.Subtotal GroupBy:=6, Function:=xlSum, TotalList:=Array(7, 8, 9, 10), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
By itself, the code fails because the array is not defined.  

I then tried :
Dim myArray As Array = Array.CreateInstance(GetType(Excel.XlRowCol), 1)
.Selection.Subtotal(GroupBy:=6, Function:=10, TotalList:=myArray(7), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True)
The error for this is System.IndexOutOfRangeException:  Index was outside the bounds of the array.

AND

Dim myArray As Array = Array.CreateInstance(GetType(Excel.XlRowCol), 4)
.Selection.Subtotal(GroupBy:=6, Function:=10, TotalList:=myArray(7, 8, 9, 10), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True)
Each time I receive
System.RankException: Attempted to operate on an array with the incorrect number of dimensions.

Can anyone help with the correct code to perform this task?

Thanks

RichW
0
Comment
Question by:RichW
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 12202892
How many dimensions does MyArray have?  

What type of array are you trying to pass?  I think that you meant to create an array like this:

Dim myArray As Integer() = {7, 8, 9, 10)

.Selection.Subtotal(GroupBy:=6, Function:=10, TotalList:=myArray, _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True)

Bob
0
 
LVL 4

Author Comment

by:RichW
ID: 12203634
Thank you, Bob.  That worked perfectly!

RichW
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

895 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

14 Experts available now in Live!

Get 1:1 Help Now