Chart Workout 2
- 03:28
Workout to demonstrate how to change the ChartType property of an series object in an embedded chart
Transcript
In this workout, we are required to write VBA code to change the EV EBITDA FY 1 series on our chart below to a line chart type.
If we select the chart, we can see that the chart is named Chart 4. Here in the name box.
And the second data series is the EV EBITDA FY 1 series.
This will be important because as we write our Excel VBA code, we must ensure that we are correctly identifying the chart and the series that we wish to change.
Let's go into the Visual Basic editor and write our code.
We'll insert a module and let's call this one Workout 2.
When we identify our required chart, we must first specify the worksheet object that our chart is embedded in, and our chart sits in the worksheet named workouts.
So let's identify our worksheet object.
The worksheet object of workouts is identified.
Next, we identify the chart objects collection.
This is the collection of all of the chart objects that sit within our worksheet, and we want to specifically identify the chart object of Chart 4.
We use the chart property to identify the specific chart object and then within that chart object we use series collection to identify the specific series that we want to change.
The chart has a series collection of objects and we want to identify the second of those data series are EV to ebitda FY 1 series.
Once we've identified that data series object, we specify the chart type property and we make this equal to XL line. Let's go Back to the front end of the Excel and check our code works back in the front end of Excel.
Developer view macros Workout 2.
We can see that when the code is executed EV over ebitda, FY 1 has been changed to a line type.