=Test2(5)
将代码放入模块后,在 Excel 中键入。为什么这会给我一个Byref argument type mismatch
错误?
如果在一开始Test2
我做一行来创建我的数组:
Dim X1(5), X2(5) As Double
,然后它会工作。但是当我b
从函数的参数列表中使用时,我必须ReDim
(因为b
是变量,而不是常量),这会导致错误。
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