Solved

How to create an Excel Groups and Subtotals

Posted on 2004-10-01
2
583 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

737 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