【发布时间】:2015-08-10 16:58:03
【问题描述】:
我是 VBA 中的数组的新手,这在 MatLab 中要容易得多,但我似乎无法让代码工作。简单来说,我正在计算一个指数的 LN 每日收益:LN(t0 / t1) 下面是代码:
Dim Index() As Variant
Dim Ret() As Variant
Index = Range("B9:B29")
For i = 1 To UBound(Index) - 1
Ret(i, 1) = Log(Index(i, 1) / Index(i + 1, 1))
Next i
我在 Ret(i,1) 循环中遇到错误。任何帮助将不胜感激!
【问题讨论】:
-
您必须先
ReDim Ret(1 to UBound(Index) - 1, 1 to 1),然后才能向其添加任何值。 -
谢谢!我现在在同一行出现溢出错误 [Ret(i,1) = Log(index....)