[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Help with Arrays - making a total formula

Dan Rolfe

12/18/2006 3:09:00 PM

I have some data..

A - B - C
--------------
a - 1 - 12
a - 2 - 13
a - 3 - 14
b - 4 - 15
b - 5 - 16
b - 6 - 17


i have the code to group the data by column A, and list column B as the
Item Id, with C as the value
all that works fine..

for the group header i have a total. my problem is that I having
trouble making an array for the total of all the totals.

The code itself is a Do loop exiting when there is no more data in the
table to read.

I guess basically what I am asking, is how can I add fields to the
array on the fly, and then reference it at the end and produce a total
of all of my totals.

2 Answers

Tom Ogilvy

12/18/2006 3:37:00 PM

0

Perhaps this pseudo code will give you some ideas

dim subtot() as long
Dim gTot as Long
Dim cell as Range
redim subtot(1 to 1)
for each cell in selection

' your logic which builds the subtotal

subtot(ubound(subtot)) = "your subtotal
redim preserve subtot(1 to ubound(subtot)+1)
Next

for i = lbound(subtot) to ubound(subtot) - 1
gTot = gTot + subtot(i)
Next
msgbox gTot


But unless you need each subtot, why not just use a separate accumulator
variable to build the grandtotal

--
Regards,
Tom Ogilvy


"drolfe@nelsonwatson.com" wrote:

> I have some data..
>
> A - B - C
> --------------
> a - 1 - 12
> a - 2 - 13
> a - 3 - 14
> b - 4 - 15
> b - 5 - 16
> b - 6 - 17
>
>
> i have the code to group the data by column A, and list column B as the
> Item Id, with C as the value
> all that works fine..
>
> for the group header i have a total. my problem is that I having
> trouble making an array for the total of all the totals.
>
> The code itself is a Do loop exiting when there is no more data in the
> table to read.
>
> I guess basically what I am asking, is how can I add fields to the
> array on the fly, and then reference it at the end and produce a total
> of all of my totals.
>
>

Dan Rolfe

12/18/2006 4:55:00 PM

0

I appreciate the prompt response, and thank you for the array code. I
ended up using the subtotal variable like you suggested. Jobs done!
thank you sir

Tom Ogilvy wrote:
> Perhaps this pseudo code will give you some ideas
>
> dim subtot() as long
> Dim gTot as Long
> Dim cell as Range
> redim subtot(1 to 1)
> for each cell in selection
>
> ' your logic which builds the subtotal
>
> subtot(ubound(subtot)) = "your subtotal
> redim preserve subtot(1 to ubound(subtot)+1)
> Next
>
> for i = lbound(subtot) to ubound(subtot) - 1
> gTot = gTot + subtot(i)
> Next
> msgbox gTot
>
>
> But unless you need each subtot, why not just use a separate accumulator
> variable to build the grandtotal
>
> --
> Regards,
> Tom Ogilvy
>
>
> "drolfe@nelsonwatson.com" wrote:
>
> > I have some data..
> >
> > A - B - C
> > --------------
> > a - 1 - 12
> > a - 2 - 13
> > a - 3 - 14
> > b - 4 - 15
> > b - 5 - 16
> > b - 6 - 17
> >
> >
> > i have the code to group the data by column A, and list column B as the
> > Item Id, with C as the value
> > all that works fine..
> >
> > for the group header i have a total. my problem is that I having
> > trouble making an array for the total of all the totals.
> >
> > The code itself is a Do loop exiting when there is no more data in the
> > table to read.
> >
> > I guess basically what I am asking, is how can I add fields to the
> > array on the fly, and then reference it at the end and produce a total
> > of all of my totals.
> >
> >