VBA:计算LN每日收益 - 下标超出范围

时间:2015-08-10 16:58:03

标签: excel vba excel-vba

我是VBA中的数组新手,这在MatLab中要容易得多,但我似乎无法让代码工作。简单地说,我正在计算索引的LN每日回报:LN(t0 / t1)以下是代码:

Frequency metric,Problem Symptom Title,Problem Symptom Desciption,Icon,Possible Cause,Troubleshooting Path,Action Step
2,Spindle issues,"When its time to run the job, the spindle doesn't run smoothly or doesn't work at all.",spindle_issue.png,Toggle switch on power supply is in the wrong position,Check toggle switch,"If using PWM, make sure it's set to ""Logic"""

我在Ret(i,1)循环中出错。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

找到它,当ReDim它将Return转换为单维数组时。所以Ret(i,1)应该是Ret(1)。我想知道为什么Index = Range返回二维数组?

Dim Index() As Variant
    Dim Ret() As Variant


    Index = Range("B9:B29")

    ReDim Ret(1 To UBound(Index) - 1)


    'Debug.Print Index(1, 1)


    For i = 1 To UBound(Index) - 1

        Ret(i) = Log(Index(i, 1) / Index((i + 1), 1))

    Next i