A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
I did not recall the Evaluate method, and although it appears to work for an on-spreadsheet function, it doesn't actually help me deal with an array I've already loaded into VBA memory.
This works:
Sub evalu8()
MsgBox ActiveSheet.Evaluate("Max(d1:d65537)")
End Sub
As does:
Sub evalu8()
MsgBox Application.Max(ActiveSheet.Range("$d$1:$d$65537"))
End Sub
but I can not get it to refer to an array in memory.
You have to go to a sheet and re-read cells each time you want to run a computation.
(but this might be efficient enough for my purposes - I'll give it a try)
Also, I think Evaluate has to return a single answer, and not a range.
This works:
Sub evalu8()
MsgBox ActiveSheet.Evaluate("Max(Index(a1:g65537,0,4))")
End Sub
But this does not:
Sub evalu8()
Dim onecol() As Variant
Erase onecol: ReDim oncecol(65536, 1)
onecol = ActiveSheet.Evaluate("Index(a1:g65536,0,4)")
MsgBox Application.Max(onecol)
End Sub
Regarding 65536 or 2^16, yes that was the old row limit. I'm speculating the old limit had something to do with integers per two's compliment binary math: 10,000,000,000,000,000 (base 2) can be thought of either as 65,536 or as -32,767. Whether it's 1 to 65,536 or -32,768 to 32,767, 16 bits will only get you 2^16 distinct numbers for rows. The row and column limits are and were always powers of 2.
Hi Peter,
If you will only get the MAX of the returned values, you can combine multiple formulas:
Sub Array_Copy_Test()
Dim source_array As Range
Dim onecol As Variant
Set source_array = Sheets("rawdata").Range("$a$1:$g$65537")
onecol = Evaluate("Max(Index(" & source_array.Address& ", 0, 4))")
MsgBox onecol
'index function will not work if number of rows is greater than the integer limit of 65536
End Sub
If you need all values then this will work:
Sub Array_Copy_Test2()
Dim source_array As Range
Dim onecol As Variant
Set source_array = Sheets("rawdata").Range("$a$1:$g$65537")
onecol = Evaluate("Index(" & source_array.Address & ", 0, 4)")
Debug.Print onecol(1, 1), onecol(2, 1)
'index function will not work if number of rows is greater than the integer limit of 65536
End Sub
The Integer definition has nothing to see with the number of rows. Earlier versions of Excel had 8192 & 16256 rows while an Integer has always been between -32727 & 32728.