Access the array resulting from LinEst function

Mofasa777

New Member
Joined
Apr 30, 2016
Messages
20
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:


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?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,226,739
Messages
6,192,739
Members
453,755
Latest member
IQBS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top