Type =Test2(5) into Excel after you put the code into a module. Why does this give me a Byref argument type mismatch error?
If in the start of Test2 I do one line to create my arrays:
Dim X1(5), X2(5) As Double, then it’ll work. But when I use b from the function’s argument list, I have to ReDim (because b is a variable, not a constant), which then causes the error.
Function Test1(a As Double)
Test1 = a * 2
End Function
Function Test2(b As Integer)
Dim X1(), X2() As Double
ReDim X1(b), X2(b) As Double
Dim i As Integer
For i = 0 To b
X1(i) = i
X2(i) = Test1(X1(i))
Next i
Test2 = X2(1)
End Function
This:
only declares
X2()as double,X1()will store the type ofb(integer) instead ofbconverted to a double (and so prevent passingAs Double).To make them both double you must repeat the type declaration;
Which will mean the correct double type is passed to
Test1