Using the Macro Recorder

Vertex42 The Excel Nexus

Professional Excel Templates

Get Instant Access

If you select cells A3:D7 and turn on the macro recorder before creating the chart in Figure 8-4, you will get code like the following:


ActiveChart.SetSourceData Source:=Range("Sales!$A$3:$D$7"), PlotBy:= _

xlColumns Selection.Name = "MangoesChart" ActiveChart.ChartType = xlColumnClustered ActiveChart.PlotBy = xlRows

ActiveChart.SetElement (msoElementChartTitleCenteredOverlay) ActiveChart.ChartTitle.Text = "Mangoes" ActiveChart.ChartArea.Select

The recorded macro is similar to the one that created a chart sheet, with some interesting differences. Whereas most lines refer to the ActiveChart object, the code that names the ChartObject refers to Selection, which is the Shape or ChartObject containing the Chart object.

The title of the chart is created using the SetElement method. This method has more than 100 constants with self-explanatory names that you can use to change the appearance of the chart. You can find these constants listed in the Object Browser.

Was this article helpful?

0 0
The Accidental Blogging Millionaires

The Accidental Blogging Millionaires

Get Inspired By The Most Popular Bloggers Online! If You Want To Skyrocket Your Success With Business And Improve Your Overall Life You Need To Have A Look At The Accidental Blogging Millionaires! Business can be a fight, particularly when you’re trying to establish one online and like all fights, to succeed you must find the winning techniques and apply them.

Get My Free Ebook

Post a comment