How to Add a Trendline to a Stacked Bar Chart in Excel (2 Methods)

Dataset Overview

We’ll use the following dataset that contains the sales data of three shops for the first six months of the year:

how to add a trendline to a stacked bar chart in excel


Method 1 – Using the Series Lines Feature

  • Select the data range (B4:E10) and go to the Insert tab.
  • Choose 2-D Bar and select Stacked Bar Chart.

  • Format the chart as needed (e.g., adjust borders).
  • The sales amount of these shops is classified by a particular set of colors: Blue, Red, and Gray are for Shop A, B, and C respectively.

how to add a trendline to a stacked bar chart in excel

  • Select the chart and go to Chart Design.
  • Click Add Chart Element, choose Lines  and select Series Lines.

  • The Series Lines in the Stacked Bar Chart will be displayed. The gridlines were removed to improve the visual effect.

how to add a trendline to a stacked bar chart in excel

  • Customize the appearance by right-clicking on the series lines and selecting Format Series Lines.

  • Select the option from the Format Series Lines window to change the appearance of the Series Lines.
  • Select the Solid Line as the Line option, increased the width to 25 pt, and changed the Dash type.

how to add a trendline to a stacked bar chart in excel

The Stacked Bar Chart looks like the following image:

Result: Your Stacked Bar Chart now includes trendlines created using the Series Lines feature.

Read More: How to Create Trend Chart in Excel


Method 2 – Using VBA (Visual Basic for Applications)

  • Go to the Developer tab and click Visual Basic.

how to add a trendline to a stacked bar chart in excel

  • Insert a new module.

  • Insert the following code in the module:
Sub StackedBarChartTrendline()
    Range("B4:E10").Select
    ActiveSheet.Shapes.AddChart2(297, xlBarStacked).Select
    ActiveChart.SetSourceData Source:=Range("'vba'!$B$4:$E$10")
    ActiveChart.ChartGroups(1).HasSeriesLines = True
End Sub

how to add a trendline to a stacked bar chart in excel

This code uses the Range.Select property and xlBarStacked Enumeration to make a Stacked Bar Chart based on the range B4:E10.

  • Return to your sheet and execute the macro.

The Stacked Bar Chart will now have series lines acting as trendlines.

how to add a trendline to a stacked bar chart in excel

Remember to format these lines as needed, following the procedure described in the previous method. We can consider them as Stacked Trendlines for this chart.

You’ve successfully added trendlines to your Stacked Bar Chart using Excel VBA.

Read More: How to Create Monthly Trend Chart in Excel


Practice Section

The dataset of this tutorial is available to you so that you can practice these methods on your own.

how to add a trendline to a stacked bar chart in excel


Download Practice Workbook

You can download the practice workbook from here:


Related Articles


<< Go Back To Add a Trendline in Excel | Trendline in Excel | Excel Charts | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Meraz Al Nahian
Meraz Al Nahian

Md. Meraz Al Nahian has worked with the ExcelDemy project for over 1.5 years. He wrote 140+ articles for ExcelDemy. He also solved a lot of user problems and worked on dashboards. He is interested in data analysis, advanced Excel, statistics, and dashboards. He also likes to explore various Excel and VBA applications. He completed his graduation in Electrical & Electronic Engineering from Bangladesh University of Engineering & Technology (BUET). He enjoys exploring Excel-related features to gain efficiency... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo