Can an array be used within the LinEst function in VBA?

前端 未结 2 473
轮回少年
轮回少年 2021-01-14 00:38

Basically, rather that selecting a range from cells I have stored values in an array through the use of a loop. What I would ideally like to do is use these arrays as the kn

2条回答
  •  星月不相逢
    2021-01-14 01:12

    Yes, it can be done. The code snippet below should help get you started:

        Dim x() As Variant
        ReDim x(1 To 3)
        x(1) = 1
        x(2) = 2
        x(3) = 3
    
        Dim y() As Variant
        ReDim y(1 To 3)
        y(1) = 4
        y(2) = 5
        y(3) = 6
    
        Dim z() As Variant
        z = WorksheetFunction.LinEst(x, y)
    

    The function returns a Variant which "boxes" an array of Variant (which will be either one- or two-dimensional). The other two parameters (not shown above) are either True or False. The function is otherwise detailed in the Excel Help.

提交回复
热议问题