Dataset Overview
We’ll use the following dataset that contains the sales data of three shops for the first six months of the year:
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.
- 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.
- 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.
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.
- 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
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.
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.
Download Practice Workbook
You can download the practice workbook from here:
Related Articles
- How to Add Trendline Equation in Excel
- How to Find Unknown Value on Excel Graph
- How to Extend Trendline in Excel
- How to Exclude Data Points from Trendline in Excel
- [Solved]: Trendline Option Not Showing in Excel
- How to Add Trendline in Excel Online
<< Go Back To Add a Trendline in Excel | Trendline in Excel | Excel Charts | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!