Chart Workout 1
- 02:26
Workout to demonstrate how to change the ChartType property of an embedded chart.
Transcript
In this workout, we are required to write VBA code to change the chart below to a line chart.
If we select the chart, we can see that this chart has the name Chart 2.
This will be important when we come to identify the chart as we are writing our visual basic code.
Let's go to the Visual basic editor and write our code developer Visual Basic.
And we want to insert a module.
This is where we'll write our code.
Let's call our procedure Workout1.
In order to identify the chart, we have to specify the worksheet where the chart sits.
The chart sits in the workouts worksheet.
So first of all, let's specify the workouts worksheet object.
Within that worksheet object.
We have a chart objects collection, and we want to specify within that collection of chart objects the chart named Chart 2.
The chart property is then applied to return the actual chart object.
The chart type property can then be applied and we want to set the chart type property to Excel line.
Let's go back into the front end of Excel and run our code.
Back in the front end of Excel, we go to developer view macros and we will run our macro.
We can see that when the macro is executed, the chart type is changed to Excel line.