Chart Properties and Methods Part 1
- 01:21
How to use the AddChart method to dynamically create embedded charts.
Downloads
No associated resources to download.
Transcript
The add chart method of shapes.
A chart object is a type of shape object can be used to dynamically create charts in a procedure.
The example procedure displays Excel VBA code to create a chart within an Excel worksheet and populate the chart with data.
Let's walk through the code. A chart object variable is declared, named my chart.
A range object variable is declared named data range.
The data range object variable is set to the range, A 1 to C 7 in the active sheet.
This will be the data range for the chart.
The new chart is assigned to the my chart object variable using the add chart method of the shapes collection add chart has five optional arguments.
Note, none of those optional arguments are specified. In this example, the set source data method of the MyChart object is used to add data to the chart.
Set source data has one required range object parameter.
The source, which in this example, is set to equal the range object variable data range.