Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to create chart

I am trying to create a chart based on the fields selected in the
worksheet. The chart loads fine, but I am getting this error:

Runtime error 1004
Method 'SetSourceData' of Object '_Chart' failed

Here's the Macro:
Sub Macro1()
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined,
TypeName:="PMS"

----Line I get error on:
ActiveChart.SetSourceData
Source:=Application.ActiveWindow.ActiveCell, PlotBy:= _
xlColumns


ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = = "Title"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = =
"Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Data = "
End With
End Sub


Does anyone have any idea why I'm getting this error? This is in Excel
2003. Thank you in advance!

Jill

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Macro to create chart

Jill,

You are telling Excel to plot a chart based upon a single data point...
"ActiveCell". That is my guess as to what is causing the problem.
Try using "Selection" or the specific range with the data.

Regards,
Jim Cone
San Francisco, USA


"JGeorge" wrote in message ups.com...
I am trying to create a chart based on the fields selected in the
worksheet. The chart loads fine, but I am getting this error:

Runtime error 1004
Method 'SetSourceData' of Object '_Chart' failed

Here's the Macro:
Sub Macro1()
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined,
TypeName:="PMS"

----Line I get error on:
ActiveChart.SetSourceData
Source:=Application.ActiveWindow.ActiveCell, PlotBy:= _
xlColumns


ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = = "Title"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = =
"Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Data = "
End With
End Sub


Does anyone have any idea why I'm getting this error? This is in Excel
2003. Thank you in advance!

Jill

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Macro to create chart

Jill -

As soon as you create the chart, it becomes the active sheet, and
there's no active cell.

Sub Macro1()
Dim ChartRange as Range

Set ChartRange = ActiveCell

Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined, _
TypeName:="PMS"

ActiveChart.SetSourceData _
Source:=ChartRange, _
PlotBy:=xlColumns

'' etc.


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

JGeorge wrote:

I am trying to create a chart based on the fields selected in the
worksheet. The chart loads fine, but I am getting this error:

Runtime error 1004
Method 'SetSourceData' of Object '_Chart' failed

Here's the Macro:
Sub Macro1()
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined,
TypeName:="PMS"

----Line I get error on:
ActiveChart.SetSourceData
Source:=Application.ActiveWindow.ActiveCell, PlotBy:= _
xlColumns


ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = = "Title"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = =
"Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Data = "
End With
End Sub


Does anyone have any idea why I'm getting this error? This is in Excel
2003. Thank you in advance!

Jill

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Chart using a Macro Scott_goddard Charts and Charting in Excel 1 April 8th 10 10:26 AM
Macro to create a new chart kimbobo Charts and Charting in Excel 1 August 18th 06 02:44 PM
VB Macro to Create a Chart [email protected] Excel Discussion (Misc queries) 0 August 15th 06 10:25 PM
Setting up Macro to create pie chart. Hamish Charts and Charting in Excel 2 August 8th 06 02:30 PM
macro to create a chart alldreams Excel Programming 2 March 1st 04 09:47 PM


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"