Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba chart

ResolvedVersion 2007

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








Sun 10 Jul 2011: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Toggle Formulas and Results

Ctrl + 'The key above Tab with the

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.08 secs.