A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Try (copy and paste both the Sub and Function in a module and then run the Sub LINEST_in_VBA_Test_2a
'Credit: Function XArray is taken from Tushar Mehta's article http://www.tushar-mehta.com/publish_train/data_analysis/16.htm
Sub LINEST_in_VBA_Test_2a()
Dim output As Variant, x As Variant, y As Variant, z As Variant
Set x = Range("c5:C18")
Dim XArr()
XArr = XArray(x.Value, 4)
Set y = Range("D5:D18")
output = Application.LinEst(y, XArr, 1, 1)
'The following code puts the output onto the current sheet
For I = 1 To UBound(output, 1)
If I = 1 Then Cells(43 + I, 13).Value = "Slope & Intercept"
If I = 2 Then Cells(43 + I, 13).Value = "+ or - "
If I = 3 Then Cells(43 + I, 13).Value = "r squared & s(y)"
If I = 4 Then Cells(43 + I, 13).Value = "F & df"
If I = 5 Then Cells(43 + I, 13).Value = "regression & ss"
For J = 1 To UBound(output, 2)
Cells(42 + I + 1, 13 + J).Value = output(I, J)
Next J
Next I
End Sub
Function XArray(InArr, PolyPower)
' taken from Tushar Mehta's article http://www.tushar-mehta.com/publish_train/data_analysis/16.htm
Dim XArr()
Dim I As Long, J As Long
ReDim XArr(LBound(InArr) To UBound(InArr), 1 To PolyPower)
For I = LBound(XArr, 1) To UBound(XArr, 1)
XArr(I, 1) = InArr(I, LBound(InArr, 2))
For J = 1 To PolyPower
XArr(I, J) = XArr(I, 1) ^ J
Next J
Next I
XArray = XArr
End Function