Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create an Excel Groups and Subtotals

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

688 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