Search : in
By :

Excel Macro to create a chart

Last answer on Aug 15, 2009 10:08:45 pm BST lanky, on Feb 19, 2009 5:49:43 pm GMT 
 Report this message to moderators

Hello,

I have recorded the Excel macro 'ChartTestMacro2' below, that creatats a chart from the Sheet "MacroTestSheet". I have been unsucessful in modifying it to work for any currently selected sheet of similar structure/format. i.e. I have been unable to find the syntax to change the line -

ActiveChart.SetSource Data Source:=Sheets("MicroTestSheet").Range(

I have tried removing "Sheets("MicroTestSheet") and the STOP . from the line however the debug then dislikes the line

Range("C:C,E:E").Select

I would appreciate some advice - I believe that I am missing something obvious

In addition how might the Range accomodate different length of data i.e. instead of (C1:C40,E1:E40) as below it could accompdate (C1:Cxx,E1,Exx).


Sub ChartTestMacro2()

Range("C:C,E:E").Select
Range("E1").Activate
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("MacroTestSheet").Range( _
"C1:C40,E1:E40"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="MacroTestChart2"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Chart Created by Test Macro"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X Axis"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y Axis"
End With
End Sub

in anticipation, Thank to respondents.

Configuration: Windows XP
Internet Explorer 7.0

Best answers for « Excel Macro to create a chart » in :
Inserting an animated gif in Excel ShowInserting an animated gif in Excel To insert an animated gif image in an Excel spreadsheet, you must insert the image into a control. To insert the control, go to the View menu/Toolbars/Control Toolbox Activate the first button Design...
Management Chart ShowThe Concept of a Management Chart A management chart is a comprehensive graphic representation of a set of indicators that give a manager all the elements needed to make decisions visually and quickly. Considering its strategic value, a...

1

Dette04, on Feb 20, 2009 8:05:38 am GMT
  • +1

Hi,
try this link to get inforamation about making charts:
http://www.exceluser.com/help/chart/long001.htm
hope it helps you.

Reply to Dette04

2

 Eugene, on Aug 15, 2009 10:08:45 pm BST
  • +1

I need suggestion how to make code Vba Excel to grath function Y(X)
Eugen

Reply to Eugene