From the course: Excel VBA: Managing Files and Data

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Add or remove data series from a chart

Add or remove data series from a chart

From the course: Excel VBA: Managing Files and Data

Add or remove data series from a chart

- [Instructor] One task that can be automated in a straightforward manner using Excel VBA is to add a data series to an existing chart. And in this movie I will show you how to do that. My sample file is 05_03_AddSeries, and you can find it in the Chapter 5 folder of the Exercise Files collection. On this worksheet, I have two series of data. I have the number of room nights for days of the week, which is very important in the hotel industry, and there are two room types that we're tracking. The first is Lovejoy, which is already displayed and summarized in the chart, and the second is Thurman, which is not. So our task is to use Excel VBA to add the Thurman data to the chart. I've already started the work, so I'll go to the Visual Basic Editor by pressing Alt + F11. And here I have a subroutine called AddDataSeries. At the top, I have a variable, and it's an integer, and it counts the number of series. And below that, I have code that first activates the March worksheet. It's the…

Contents