vba chart
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

VBA chart

resolvedResolved · High Priority · Version 2007

replyReply Fri 1 Jul 2011, 16:13Delegate Pierre said...

Pierre has attended:
Excel VBA Intro Intermediate course

VBA chart

Can you write the VBA code for creating a chart automatically?

For upcoming training course dates see: Pricing & availability

replyReply Mon 4 Jul 2011, 09:34Trainer Stephen said...

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.

 

Please browse our web site to find out more about
excel training class and other Microsoft training courses.

Excel tip:

Hiding and unhiding rows using the keyboard

CTRL + 9 hides your columns and CTRL + SHIFT + ( unhides them although you would need to highlight the row letters either side as per normal

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard