RE-Post Max Function not working properly on 2D Array

E

ExcelMonkey

I have a 2D array which I set up as a 2 columns and X Rows. I transpose it
to be X Rows by 2 Columns. I then test the max of the array and get an odd
result. The code is quite extensive but here is the just.

I set a break point and I print the transposed array contents to the
Immediate window in the first loop I get the following using the code below:
For X = 0 To UBound(NumberSetArray, 1)
Debug.Print NumberSetArray(X, 0) & ","; NumberSetArray(X, 1)
Next

I get the following in the Immediate Window:
7, 49

Immediately after printing tot the Immediate Window, I test for a max value
in the Immediate window using:
?Application.WorksheetFunction.Max(Application.Index(NumberSetArray, , 1))
I get a value of 0.

Shouldn't the result be 7?

Whe I do the same test on the second column of the array I get:
?Application.WorksheetFunction.Max(Application.Index(NumberSetArray, , 2))
52

Which I know to be correct.

Have I set the Index up incorrectly when attempting to apply the min
function to the first column

Thanks

EM
 
S

sebastienm

Hi,

1. I would make sure the array returned by INDEX is correct:
Dim v
v= Application.WorksheetFunction.Index(s, , 1)
then print each element.
Same with Index(s, , 2)

2. If your 2d array correspond to a range, you can use the
Appplication.Evaluate function to get what you need, Eg:
Application.Evaluate("=max(INDEX(G3:H6,,1))")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top