Hi,
I am a newbie when it comes to writing VBA macros in Excel, so I will most likely get the jargon wrong. I have hit a dead end in searching for an explanation to an odd problem that I am having determining the size of array passed from Excel 2007 into my VBA function (macro). I will demonstrate with two examples.
Case 1 -------------------
An Excel cell has the following formula: =myFunction(A1:A6)
The macro is as follows:
Function myFunction(myArray As Variant)
Debug.Print IsArray(myArray)
myFunction = UBound(myArray, 1)
End Function
The Debug.Print statement outputs True, confirmning that myFunction is receiving an array. Yet the Excel cell evaluates to #VALUE! because of a type mismatch at the UBound assignment.
From what I have read the above should work. Contrast this with the following variation.
Case 2 -------------------
An Excel cell has the following formula: =myFunction1(A1:A6)
The macro is as follows:
Function myFunction1(myArray As Variant)
Temp = myArray
Debug.Print IsArray(Temp)
myFunction1 = UBound(Temp, 1)
End Function
This works.
-------------------
I don't understand what Temp = myArray does. Does it transfer a pointer? More importantly, why does it make the funciton work?
This is driving me nuts! Please. Help.
Cheers,
Sebulba1