View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Min Function on 2D Array

How have you declared and loaded the Array1 variable? The following example
code works as expected.

Dim Arr(1 To 3, 1 To 2) As Double
Dim Min As Variant

Arr(1, 1) = 3
Arr(1, 2) = 5
Arr(2, 1) = 7
Arr(2, 2) = 9
Arr(3, 1) = 11
Arr(3, 2) = 12

Min = Application.WorksheetFunction.Min(Arr, 2)
If IsError(Min) = True Then
Debug.Print "Error: " & CStr(Min)
Else
Debug.Print "Min: " & CStr(Min)
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"ExcelMonkey" wrote in message
...
Allan, I cannot get this line to work:

MinRow = Application.WorksheetFunction.Min(Array1, 2)

I keep getting a "Sub of Function not defined" error.

I event tried the following and recieved an "Arguement not optional" error

MinRow =
Application.WorksheetFunction.Min(Application.Work sheetFunction.Index(Array1,
, 2))

????

EM


"Alan Beban" wrote:

ExcelMonkey wrote:
Can't seem to get this to work. I am trying to calculate the min value
for
the second column in an array. The printout from my Immediate Window
tells
me this value should be 2. However the following line returns a value
of 1:

MinRow = Application.WorksheetFunction.Min(Array1, 2)

Sub MakeSenseOfArrays()
Dim Array1 As Variant
Dim MinRow As Integer

ReDim Array1(0 To 1, 0 To 2)
Array1(0, 0) = 1
Array1(0, 1) = 2
Array1(0, 2) = 3
Array1(1, 0) = 10
Array1(1, 1) = 20
Array1(1, 2) = 30

For X = 0 To UBound(Array1, 1)
Debug.Print Array1(X, 0) & " " & Array1(X, 1) & " " & Array1(X,
2)
Next

MinRow = Application.WorksheetFunction.Min(Array1, 2)

End Sub


Immediate Window:
1 2 3
10 20 30


MinRow = Application.WorksheetFunction.Min(Index(Array1,,2) )

Alan Beban