By Hemanta Sundaray on 2021-12-18
To create a new chart, we use the AddChart2 method of the Shapes collection.
The AddChart2 method can use seven arguments (all are optional):
Here is a simple procedure that creates a clustered column chart"
Note that we have not specified the NewLayout argument, so it uses the default value.
Sub ColumnChart()
Dim MyChart As Chart
Dim DataSource As Range
Set dataSource = ActiveCell.CurrentRegion
Set MyChart = ActiveSheet.Shapes.AddChart2 _
(201, xlColumnClustered, 150, 50, 300, 200).Chart
MyChart.SetSourceData Source:=DataSource
End Sub
This procedure uses two object variables: DataSource (for the Range object that holds the data) and MyChart (for the Chart object).