vba chart

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA chart

VBA chart

resolvedResolved · High Priority · Version 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:

Switch between workbooks ni EXCEL.

use Alt-TAB to switch between workbooks.

View all Excel hints and tips


Server loaded in 0.05 secs.