How to Automatically Return Excel Trendline Slope, Intercept, and R-Squared
Question details
The user wants to extract regression values (slope, intercept, R-squared) from a chart trendline directly into cells to avoid manual entry.

- 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.
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.
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.
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.
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.
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 LOGEST Function for Exponential Trendlines
If your chart trendline follows an exponential curve rather than a linear one, use the LOGEST function to extract the corresponding regression statistics.
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. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your scatter plot and raw data.
- 2. Input the statistical function: Type =LINEST(Y_range, X_range, TRUE, TRUE) into a blank cell or selected range.
- 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.

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.




