Microsoft Office Tutorials and References
In Depth Information
Creating a Chart on a Chart Sheet
Creating a chart the old way
Using the AddChart method of the Shapes collection (as described in “Creating an Embedded
Chart”) is the “new” way of creating charts, introduced in Excel 2007. For compatibility
purposes, you can still use the Add method of the ChartObjects collection. This method, unlike
the AddChart method of the Shapes objects, doesn’t allow you to specify the chart type as an
argument, so you need to use the ChartType property if you want to use anything except the
default chart type. In addition, the Left , Top , Width , and Height arguments are required.
The procedure that follows uses the Add method of the ChartObjects collection to create an
embedded chart.
Sub CreateChart2()
Dim MyChart As Chart
Dim DataRange As Range
Set DataRange = ActiveSheet.Range(“A1:C7”)
Set MyChart = ActiveSheet.ChartObjects.Add(10, 10, 354, 210).Chart
MyChart.SetSourceData Source:=DataRange
MyChart.ChartType = xlColumnClustered
End Sub
Creating a Chart on a Chart Sheet
The preceding section describes the basic procedures for creating an embedded chart. To create
a chart on a chart sheet, use the Add method of the Charts collection. The Add method of the
Charts collection uses several optional arguments, but these arguments specify the position of
the chart sheet — not chart-related information.
The example that follows creates a chart on a chart sheet and specifies the data range and chart
type:
Sub CreateChartSheet()
Dim MyChart As Chart
Dim DataRange As Range
Set DataRange = ActiveSheet.Range(“A1:C7”)
Set MyChart = Charts.Add
MyChart.SetSourceData Source:=DataRange
ActiveChart.ChartType = xlColumnClustered
End Sub
Figure 18-2 shows the result.
 
Search JabSto ::




Custom Search