I have a pre-defined vba function that I've been using for other sub-routines:
Function MyFunction(MyArray() as Double)
'my code
End Function
I would like to use this function for my worksheet calculations. However, when I select a range in the worksheet as input, I get the #Value! error:
MyFunction(A1:A5) leads to #Value!
My guess with what's wrong is that I'm inputting a range when my function requires an array. What's the easiest way to get around this problem? Thanks!
Hi. If I understand your question correctly, see if stepping thru this codes helps.
Step thru the first two assignments (via F8) and then look at the locals windows.
This should show you the differences.
One way to match the range with an array might be:
Sub Demo()
Dim v, A
v = Range("A1:A5")
A = Array(1, 2, 3, 4, 5)
' Match V to an array
v = WorksheetFunction.Transpose(v)
End Sub