Pierre has attended:
Excel VBA Intro Intermediate course
VBA chart
Can you write the VBA code for creating a chart automatically?
RE: VBA chart
Hi Pierre
Thanks for your question
The following procedure is taken from our advanced course and creates a chart automatically from data on a worksheet and then formats it
Sub ColumnClustered()
Dim aChart As Chart
Dim intRows As Integer
Dim intColumns As Integer
ActiveSheet.ChartObjects.Delete
Set aChart = Charts.Add
intRows = Sheets("Employee List").Range("N3").CurrentRegion.Rows.Count
intColumns = Sheets("Employee List").Range("N3").CurrentRegion.Columns.Count
Set aChart = aChart.Location(Where:=xlLocationAsObject, Name:="Employee List")
Sheets("Employee List").Select
With aChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("Employee List").Range("N3").CurrentRegion
.HasTitle = True
.ChartTitle.Text = "Salary Per Job Title"
With .Parent
.Top = Range("A20").Top
.Left = Range("A20").Left
.Name = "SalesAnalysis"
End With
End With
End Sub