newbie question on multi-dimensional array

  • Thread starter Thread starter sammus
  • Start date Start date
S

sammus

Hi all,

I have a real lame question about multi-dimensional array operation.
Suppose I have defined a two-dimensional array "Array(10,10)". If I
want to use the Excel function "Average" to compute the average value
of Column, say 10, of that 2D array, is there any way to realize it? I
tried "Application.Average(Array(:,10))", but apparently the Excel
doesn't like that. (You can see I am a Matlab guy, so please don't
laugh at me:) )
Any comments are extremely welcome.
 
s,
'---------------------
Sub ArrayTest()
Dim i As Long
Dim j As Long
Dim arrNums() As Double
Dim arrCol As Variant

'11 columns
ReDim arrNums(0 To 10, 0 To 10)
'Fill the array
For i = 0 To 10
For j = 10 To 0 Step -1
arrNums(i, j) = i + j
Next
Next

'If you set row_num or column_num to 0 (zero), then
'Index returns the array of values for the entire column or row

arrCol = Application.Index(arrNums, 0, 10) 'next to last column
MsgBox Application.Average(arrCol)
End Sub
'------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



in message...
Hi all,
I have a real lame question about multi-dimensional array operation.
Suppose I have defined a two-dimensional array "Array(10,10)". If I
want to use the Excel function "Average" to compute the average value
of Column, say 10, of that 2D array, is there any way to realize it? I
tried "Application.Average(Array(:,10))", but apparently the Excel
doesn't like that. (You can see I am a Matlab guy, so please don't
laugh at me:) )
Any comments are extremely welcome.
sammus
 
Back
Top