Linear regression slope over variable range

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I want to return the linear regression slope (in cell N4) of the last 5 values in a data set. The data set begins on row 8 in columns C (x values) and AA (y values). The last row with data in these columns will vary which is why I can't use the cell formula:
Code:
=SLOPE(C255:C259,AA255:AA259)

Can anyone modify this formula to work regardless of the number of rows? And although I stated that I wanted the linear regression slope for the last 5 values, it would be great I could set the number of values included the calculation based on the value in cell AA2.

Thanks,

Art
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Maybe...
Code:
=SLOPE(INDEX(C:C,   MATCH(9E+307, C:C  )):INDEX(C:C,   MATCH(9E+307, C:C  )-4), 
       INDEX(AA:AA, MATCH(9E+307, AA:AA)):INDEX(AA:AA, MATCH(9E+307, AA:AA)-4))
 
Upvote 0
shg,

Thanks so much, works perfectly.

Art
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,767
Members
452,940
Latest member
rootytrip

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