我是VBA的新手,并试图学习如何获得6次多项式的系数。到目前为止,这是我的代码,每次使用它时都会出现值错误。
编辑:将krw定义中的M和kro分别修改为M_1和kro_1
Function krw(M_1 As Range, kro_1 As Range, S_bar_W2 As Double)
linest_1 = Application.LinEst(M_1, Application.Power(kro_1, Array(1, 2, 3, 4, 5, 6)))
index_1 = Application.WorksheetFunction.Index(linest_1, 1) * S_bar_W2 ^ 6
index_2 = Application.WorksheetFunction.Index(linest_1, 1, 2) * S_bar_W2 ^ 5
index_3 = Application.WorksheetFunction.Index(linest_1, 1, 3) * S_bar_W2 ^ 4
index_4 = Application.WorksheetFunction.Index(linest_1, 1, 4) * S_bar_W2 ^ 3
index_5 = Application.WorksheetFunction.Index(linest_1, 1, 5) * S_bar_W2 ^ 2
index_6 = Application.WorksheetFunction.Index(linest_1, 1, 6) * S_bar_W2 ^ 1
index_7 = Application.WorksheetFunction.Index(linest_1, 1, 7)
krw = index_1 + index_2 + index_3 + index_4 + index_5 + index_6 + index_7
End Function