вам нужно позднее связать формулу и использовать Application.Power
были некоторые другие проблемы логики c, которые я исправил.
Public Function ReturnArrayAtoB(ByVal M As Long, ByVal N As Long) As Variant
Dim arrReturn As Variant
ReDim arrReturn(N - M)
Dim lngCounter As Long
For lngCounter = 0 To N - M
arrReturn(lngCounter) = M + lngCounter
Next lngCounter
ReturnArrayAtoB = arrReturn
End Function
Function PolyFit(rX As Range, rY As Range, Xinput As Double, Optional PolyOrder = 3)
Dim arrReturn As Variant
arrReturn = ReturnArrayAtoB(1, PolyOrder)
Dim varLinEst As Variant
varLinEst = Application.LinEst(rY, Application.Power(rX, arrReturn))
Dim a As Double
a = 0#
Dim i As Long
For i = 1 To PolyOrder + 1
a = (Xinput ^ (PolyOrder + 1 - i)) * varLinEst(i) + a
Next i
PolyFit = a
End Function
И только потому, что следующая формула делает то же самое, если есть Sequence ():
=SUMPRODUCT(INDEX(LINEST(B1:B8,(A1:A8^SEQUENCE(,E2))),SEQUENCE(E2+1)),E1^(SEQUENCE(E2+1,,E2,-1)))