View Full Version : Solved: N Dimension Arrays

01-16-2009, 10:28 AM
Hi guys!

I'm working with an array of 31x63
Where the 31 rows are for the days of the month and the columns 0 to 60 for the days a taks took to finish. The day in the row indicates the the task was completed.what i need is to obtain the total amount in the columns and rows of tha array.

I mean I would increase a row in the array to store the total of each column and in a new column i will save the sum of each row.

if i work with a 1 dimension array i use the instruction application.sum(array) to obtain the total

but there must be some kind of instruction to do the same but with each column and row of the array, but i just don't know the instruction.

can anybody help me?



Bob Phillips
01-16-2009, 10:36 AM
An array can be columns and rows!

Post an example of what you mean, it is not clear.

01-16-2009, 10:47 AM
Assume that from a query i create an array with the following data:
123 236 258 457 455
544 847 620 120 233
322 514 214 625 124
OK from the aboce message, this array is 3x5.
And i would like to know if there a function or statment that calculate the sum of the rows, ie row1=123 + 236 + 258 + 457 + 455=1529
the same for the columns
what i know is that if you use application.sum(array) the result is the sum of all the elements of the array.
But i need the sum of each row and column

Bob Phillips
01-16-2009, 11:06 AM
Sub test()
Dim ary As Variant
Dim i As Long

ary = [{123,236,258,457,455;544,847,620,120,233;322,514,214,625,124}]

For i = LBound(ary, 1) To UBound(ary, 1)

Debug.Print "Row " & i & ":= " & Application.Sum(Application.Index(ary, i))
Next i

For i = LBound(ary, 2) To UBound(ary, 2)

Debug.Print "Column " & i & ":= " & Application.Sum(Application.Index(ary, , i))
Next i
End Sub

01-16-2009, 11:23 AM