Function Problems

How to Automatically Return Excel Trendline Slope, Intercept, and R-Squared

Nimra MalikNimra Malik Nov 11, 2026 868 views

Question details

The user wants to extract regression values (slope, intercept, R-squared) from a chart trendline directly into cells to avoid manual entry.

How to Automatically Return Excel Trendline Slope, Intercept, and R-Squared
Product
Excel
Device & OS
not provided
Scenario
Performing statistical or regression analysis where trendline equation coefficients are needed for further calculations.
Observed behavior
The goal is to automate the retrieval of chart trendline data directly into worksheet cells for easier referencing.
Before you start

Ensure your dataset contains matched pairs of x and y values without empty cells or text strings, as regression functions require continuous numeric data arrays to calculate accurate statistics.

Solution 1Recommended

Use the LINEST Function for Linear Regression

The LINEST function calculates the statistics for a line by using the 'least squares' method to calculate a straight line that best fits your data.

LINEST is an array function that can return the slope, y-intercept, and R-squared value simultaneously. To output the R-squared value along with the coefficients, you must set the fourth argument (stats) to TRUE.

1
Select the output range

Highlight a 5-row by 2-column range of blank cells where you want the regression statistics to appear. If you only need the slope and intercept, a 1-row by 2-column range is sufficient.

2
Enter the formula

Type =LINEST(known_y's, known_x's, TRUE, TRUE) in the formula bar, replacing the arguments with the actual cell ranges of your data.

3
Execute as an array formula

Press Ctrl + Shift + Enter (or just Enter if you are using a newer version of Excel with dynamic arrays support) to populate the cells with the regression values.

Use the LINEST Function for Linear Regression
Understanding the Array Output: The top-left cell displays the slope, the cell immediately to its right shows the y-intercept, and the cell in the third row of the first column displays the R-squared value.
Free Spreadsheet Software

Calculate Regression Values Easily with WPS Spreadsheet

WPS Spreadsheet fully supports advanced statistical functions like LINEST and LOGEST, allowing you to seamlessly analyze regression data and extract trendline values just like in Excel.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your scatter plot and raw data.
  2. 2. Input the statistical function: Type =LINEST(Y_range, X_range, TRUE, TRUE) into a blank cell or selected range.
  3. 3. Complete the array formula: Press Ctrl + Shift + Enter to instantly calculate and display the slope, intercept, and R-squared values directly in your sheet.
Fully compatible with Microsoft Excel formulas and .xlsx files.Built-in array formula support for instant regression statistics.Lightweight, fast, and completely free to use.Familiar interface makes switching and analyzing data effortless.
microsoft office alternative - wps office

Frequently Asked Questions

How do I extract just the slope or intercept without an array formula?

You can use the standalone SLOPE and INTERCEPT functions. Enter =SLOPE(known_y's, known_x's) for the slope of the linear regression line, and =INTERCEPT(known_y's, known_x's) to return the y-intercept.

How do I find the R-squared value for a linear trendline without using LINEST?

You can use the RSQ function. Enter =RSQ(known_y's, known_x's) to calculate the square of the Pearson product-moment correlation coefficient, which identically matches the R-squared value displayed on a linear chart trendline.

Why does my LINEST formula return a #VALUE! error?

This error typically occurs if the selected ranges for known_y's and known_x's are not identically sized, or if there are text values or blank cells hidden within your numeric data ranges.

Can I use the LINEST function for polynomial trendlines?

Yes, but you must modify the known_x's argument to evaluate powers of x. For example, using =LINEST(Y_range, X_range^{1,2}) will return the coefficients for a second-order polynomial (quadratic) regression.