The Recorded Macro

The recorded macro should look like the following:



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

, PlotBy:= _


ActiveChart.ChartType = xlColumnClustered



ActiveChart.PlotBy = xlRows

ActiveChart.ApplyLayout (1)


ActiveChart.ChartTitle.Text = "Mangoes"


Although you inserted a new chart sheet, the recorded macro uses the AddChart method of the Shapes object to create an embedded chart in the Sales worksheet. (Note that the recorder prefers to refer to a ChartObject as a Shape object, which is an alternative pointed out at the beginning of this chapter.) It uses the SetSourceData method to define the ranges plotted by the active chart and sets the chart's ChartType property.

The macro then uses the Add method of the Charts collection to create a new chart sheet. At this point, the embedded chart is used to create the new chart sheet. The PlotBy property changes the orientation of the chart, and the ApplyLayout method applies the selected format so that a title appears. The Text property of the ChartTitle object is assigned the string "Mangoes". Finally, the macro records that you selected the chart area.

0 0

Post a comment