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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
From my understanding the results array will be 5 rows by 6 columns?

You're right, but it will have rows 1 to 5, and columns 1 to 6.

By the way, I'm curious why you don't include 0 in Array(1, 2, 3, 4, 5)?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

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