How to Use the Excel SLOPE Function – 5 Examples

The Excel SLOPE Function

  • Description

The SLOPE function returns the slope of the linear regression line with known y and x data points. The rate of change and the regression line are calculated by dividing the vertical distance by the horizontal distance between any two locations on the line.

  • Generic Syntax

SLOPE(known_y’s, known_x’s)

  • Argument Description
ARGUMENT REQUIREMENT EXPLANATION
known_y’s Required An array or cell range of numeric dependent data points.
known_x’s Required The set of independent data points.
  • Returns

returns a numeric value.

Remarks:

This is the SLOPE equation:Overview of Excel SLOPE Function

 


Example 1 – Calculate the Slope of a Regression Line Using Excel SLOPE Function

Calculate the slope in C11:

Calculate Slope of a Regression Line Using Excel Slope Function

  • Select C11.
  • Use the following formula.
  • Press Enter.
=SLOPE(C5:C9,B5:B9)

Calculate Slope of a Regression Line Using Excel Slope Function

This is the output.

Calculate Slope of a Regression Line Using Excel Slope Function

To create a 2D line chart:

  • Select C5:C9.
  • Go to the Insert tab.
  • Select the first option in 2-D line.

Calculate Slope of a Regression Line Using Excel Slope Function

The graph is displayed.

Calculate Slope of a Regression Line Using Excel Slope FunctionTo see the profit values in the Y-axis and the sales values in the X-axis:

  • Right-click the graph and choose “Select Data”.

Calculate Slope of a Regression Line Using Excel Slope Function

  • Select Edit in Horizontal Axis Labels.

Calculate Slope of a Regression Line Using Excel Slope Function

  • In Axis label range, enter B5:B9.
  • Click OK.

The sales value are displayed in the X-axis.

  • Enter Axis Titles and Legend names in Chart Elements.

To insert a trendline:

  • Right-click the line of the graph.
  • Select Add Trendline.

This is the output.

This is the final output.


Example 2 – Use the Excel SLOPE Function to Calculate a Negative Slope

Use of Excel SLOPE Function to Calculate Negative Slope

  • Select C11.
  • Use the following formula.
  • Press Enter.
=SLOPE(B5:B9,C5:C9)

You will see a negative value in C11.

Use of Excel SLOPE Function to Calculate Negative Slope

  • Follow the steps described in the previous example to insert a graph:

Read More: How to Find the Slope of a Line in Excel


Example 3 – Combining the SLOPE and the INTERCEPT Functions

  • Select C12.
  • Use the following formula.
  • Press Enter.
=INTERCEPT(C5:C9,B5:B9)

The intercept value is displayed in C12.

Pairing SLOPE and INTERCEPT Functions Together

  • Use a new equation with the slope value and the intercept part:

Slope = m

Intercept = C

The INTERCEPT function returns the y-axis intersection point using the x-axis and the y-axis values.

Read More: How to Calculate Slope and Intercept in Excel


Example 4 – Using the Excel SLOPE Function as a VBA Function

 

Use of Excel SLOPE Function as VBA Function

Enable the Developer tab to create macro-enabled content.

  • Go to File.

Use of Excel SLOPE Function as VBA Function

  • Select Options.

Use of Excel SLOPE Function as VBA Function

  • Select Customize Ribbon.

Use of Excel SLOPE Function as VBA Function

  • Choose Developer and click OK.

Use of Excel SLOPE Function as VBA Function

The Developer tab iis displayed on the ribbon.

Use of Excel SLOPE Function as VBA Function

 

  • Go to the Developer tab.
  • Select Visual Basic.

  • Select Insert.
  • Choose Module.

  • Select Module-1.
  • Enter the following code in the blank window.
Sub SLOPE_Example()
Dim Sales As Range
Dim Profit As Range
Set Sales = Range("B5:B9")
Set Profit = Range("C5:C9")
MsgBox Application.WorksheetFunction.SLOPE(Profit, Sales)
End Sub
  • Click run or press F5 to run the code.

A message box displays the value of the slope.

Read More: How to Find Instantaneous Slope on Excel


Example 5 – The Excel Slope Function Errors

5.1 #N/A! Error 

When the specified arrays of known x’s and and known y’s have different length, the SLOPE function displays a #N/A! Error.

#N/A! Error While Using Excel SLOPE Function

  • Select C10 and use the following formula:
=SLOPE(C5:C9,B5:B10)

#N/A! Error While Using Excel SLOPE Function

  • Press Enter.
  • The #N/A! error is displayed as the value in C5:C9 is not equal to B5:B10.


5.2 The  #DIV/0! Error

The SLOPE function displays the #DIV/0! error:OPE function throws the #DIV/0! error.

  • If any of the known x’s or known y’s arrays are empty.

Calculate the slope of the following dataset:

Excel SLOPE Function giving  #DIV/0! Error

  • Select C10 and enter the following formula:
=SLOPE(C5:C9,B5:B9)

Excel SLOPE Function giving  #DIV/0! Error

  • Press Enter.
  • The  #DIV/0! error is displayed because there is an empty value in B5:B9. 

 


Download Practice Workbook

Download the practice workbook.


Excel SLOPE Function: Knowledge Hub


<< Go Back to Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mukesh Dipto
Mukesh Dipto

Mukesh Dipto is an excellent marine engineer who loves working with Excel and diving into VBA programming. For him, programming is like a superhero tool that saves time when dealing with data, files, and the internet. His skills go beyond the basics, including Rhino3D, Maxsurf C++, AutoCAD, HTML, CSS, JavaScript, and WordPress. He got his B.Sc in Naval Architecture & Marine Engineering from BUET, and now he's switched gears, working as a content developer. In this role, he... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo