Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ZZZ ZZZ is offline
external usenet poster
 
Posts: 1
Default MAX of Multidimensional Array

Hello,

Is there a way to use the MAX function on one dimension of
a multidimensional array declared in VBA? I guess the
simplest example would be a 2D array with an index number
in the first column and various numbers in column two that
you want to extract the max from.

Thanks
Zed
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default MAX of Multidimensional Array

Zed,

As long as you stick to 2 dimensions you can use the index function,
with either row or column argument set to 0

Sub TestMax()
Dim i, j, arr&()
'2 dimensional
ReDim arr&(1 To 10, 1 To 20)
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
arr(i, j) = j + i * 100
Next: Next
With Application.WorksheetFunction
MsgBox _
"Max row 3:" & vbTab & .Max(.Index(arr, 3, 0)) & vbNewLine & _
"Max col 4:" & vbTab & .Max(.Index(arr, 0, 4))
End With

End Sub

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"ZZZ" wrote:

Hello,

Is there a way to use the MAX function on one dimension of
a multidimensional array declared in VBA? I guess the
simplest example would be a 2D array with an index number
in the first column and various numbers in column two that
you want to extract the max from.

Thanks
Zed


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MAX of Multidimensional Array

Note that you are limited to arrays of 5461 elements. So for example

ReDim arr&(1 To 273, 1 To 20)

would work,

ReDim arr&(1 To 274, 1 To 20)

would not work.

In xl 2002 and later, I believe this restriction has been relaxed.

--
Regards,
Tom Ogilvy

keepitcool wrote in message
...
Zed,

As long as you stick to 2 dimensions you can use the index function,
with either row or column argument set to 0

Sub TestMax()
Dim i, j, arr&()
'2 dimensional
ReDim arr&(1 To 10, 1 To 20)
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
arr(i, j) = j + i * 100
Next: Next
With Application.WorksheetFunction
MsgBox _
"Max row 3:" & vbTab & .Max(.Index(arr, 3, 0)) & vbNewLine & _
"Max col 4:" & vbTab & .Max(.Index(arr, 0, 4))
End With

End Sub

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"ZZZ" wrote:

Hello,

Is there a way to use the MAX function on one dimension of
a multidimensional array declared in VBA? I guess the
simplest example would be a 2D array with an index number
in the first column and various numbers in column two that
you want to extract the max from.

Thanks
Zed




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional Array problem I can't solve ! Please help me out ! David Van Heuverswyn Excel Programming 3 October 6th 03 01:49 PM
multidimensional lookup? Lightspeed Excel Programming 1 September 10th 03 10:56 PM
size of multidimensional dynamic array ThatFella[_2_] Excel Programming 4 September 3rd 03 11:53 PM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 3 August 11th 03 09:01 AM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 14 August 8th 03 10:49 PM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"