I am trying to output the values of the R2 from the linEst function for all the rows of data I have using the following code:
I am getting an error at the last line when I try to access the results(2,0) array to obtain the R2 value stating the subscript is out of range. Am I doing it wrong? From my understanding the results array will be 5 rows by 6 columns?
Code:
Sub getdeflection6()
Dim xvalues() As Double, yvalues() As Double, cell As Range
Dim alldata As Range
Dim results As Variant
Dim counter As Integer
ReDim xvalues(0 To 8, 0 To 0)
ReDim yvalues(0 To 8, 0 To 0)
ReDim results(0 To 5, 0 To 6)
xvalues(0, 0) = 0
xvalues(1, 0) = Range("S2").Value
xvalues(2, 0) = Range("P2").Value
xvalues(3, 0) = Range("M2").Value
xvalues(4, 0) = Range("J2").Value
xvalues(5, 0) = Range("G2").Value
xvalues(6, 0) = Range("C2").Value
xvalues(7, 0) = Range("B2").Value
Set alldata = Range("F7", Range("F7").End(xlDown))
counter = 7
For Each cell In alldata
yvalues(0, 0) = 0
yvalues(1, 0) = cell.Offset(0, 15).Value
yvalues(2, 0) = cell.Offset(0, 12).Value
yvalues(3, 0) = cell.Offset(0, 9).Value
yvalues(4, 0) = cell.Offset(0, 6).Value
yvalues(5, 0) = cell.Offset(0, 3).Value
yvalues(6, 0) = cell.Value
yvalues(7, 0) = 0
results = Application.LinEst(yvalues, Application.Power(xvalues, Array(1, 2, 3, 4, 5)), True, True)
Cells(counter, 23) = results(2, 0)
counter = counter + 1
Next cell
End Sub
I am getting an error at the last line when I try to access the results(2,0) array to obtain the R2 value stating the subscript is out of range. Am I doing it wrong? From my understanding the results array will be 5 rows by 6 columns?