Shapes.AddChart Method (Excel)
Creates a chart at the specified location on the active sheet.
Version Information
Version Added: Excel 2007
Syntax
expression .AddChart(Type, Left, Top, Width, Height)
expression A variable that represents a Shapes object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
Type |
Optional |
XlChartType |
The chart type. |
Left |
Optional |
Variant |
The distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart). |
Top |
Optional |
Variant |
The distance, in points, from the top edge of the topmost shape in the shape range to the top edge of the worksheet. |
Width |
Optional |
Variant |
The width, in points, of the object. |
Height |
Optional |
Variant |
The height, in points, of the object. |
Return Value
Shape
Remarks
If the chart type is omitted, the default chart type for the application is used. If the position is omitted, the default size for the application is used.
Example
The following example adds a chart to the active worksheet. The data for the stacked cylinder column chart type is taken from cells A10 to B14.
Range("A10:B14").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$10:$B$14"), PlotBy:= _
xlColumns
ActiveChart.ChartType = xlCylinderColStacked