Chart Properties and Methods Part 2
- 01:42
How to modify a chart object's and series object's ChartType property.
Downloads
No associated resources to download.
Transcript
A chart object's chart type property can be changed.
The chart type property dictates what type of chart will be presented.
For example, a line chart, a column chart, etc.
Unlike in Excel, a chart does not have to be active.
The VBA method here is dot activate for the chart to be changed.
What should be noted is the syntax required to specify the different chart types.
In the example, a line chart is specified in Excel VBA Excel line.
Typically, the chart type is prefixed by xl.
For example, Excel clustered column, see Excel chart type in VBA help for all the chart types and their required syntax.
A chart object contains a series object.
The series object like other objects in Excel VBA has a set of properties.
In the example, the series object of the chart object is identified.
Series collection two is the second series. In the collection of all the series objects in the chart, the series objects, properties of values and name are each then assigned in separate lines of code.
The last line of code identifies the X values property and assigns the range of values from the Excel worksheet.
Note, the X values property can be left empty.
The VBA code in the example is a little efficient and could be made more flexible if the series number took the value from a variable.