Name

chartobjects.Add(Left, Top, Width, Height)

Synopsis

Creates a blank, embedded chart on the worksheet or chart sheet.

Argument

Settings

Left

The distance between the left edge of the sheet and the right edge of the chart in points

Top

The distance between the top of the sheet and the top of the chart in points

Width

The width of the chart in points

Height

The height of the chart in points

Add does not plot the chart, so use the ChartWizard or SetSourceData methods after you create the chart. The following code shows how to quickly create an embedded chart from a selected range of cells:

Sub AddEmbeddedChart(  )
    Dim co As ChartObject
    ' Create the chart object
    Set co = ActiveSheet.ChartObjects.Add(100, 200, 400, 200)
    ' Plot the chart from the selected range.
    co.Chart.ChartWizard Selection, xl3DColumn, , xlRows
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.