Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create an Excel Groups and Subtotals

Posted on 2004-10-01
2
Medium Priority
?
618 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 500 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

886 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