PC Review


Reply
Thread Tools Rate Thread

Chart error: plotting series data XY scatter plot

 
 
frostkiller
Guest
Posts: n/a
 
      14th Apr 2010
Hi all,

I am having trouble with my chart making macros. I am trying to create a
series XY-scatter plot of several columns (in this particular case 13
columns). My code if giving me an error, see code below between the double
asterisk highlight **...**

Do I need to plot each series at a time? Any help would be greatly
appreciated. Thanks.


For Each c In Worksheets("shift").Range(Cells(2, 2), Cells(lastRow,
lastCol)).Cells
If c.Value = "" Then c.Value = 0
Next

' here I am setting each empty cell to zero

Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="shift"
ActiveChart.ChartType = xlXYScatter
ChartOne = ActiveChart.Parent.Name
**Worksheets("shift").ActiveChart.SetSourceData Source:=Worksheets
("shift").Range(Cells(2, 2), Cells(lastRow, lastCol)), _
PlotBy:=xlColumns**

' here is where the code errors

ActiveChart.PlotArea.Select
Selection.Interior.ColorIndex = xlNone
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
 
Reply With Quote
 
 
 
 
Martin Brown
Guest
Posts: n/a
 
      14th Apr 2010
frostkiller wrote:
> Hi all,
>
> I am having trouble with my chart making macros. I am trying to create a
> series XY-scatter plot of several columns (in this particular case 13
> columns). My code if giving me an error, see code below between the double
> asterisk highlight **...**
>
> Do I need to plot each series at a time? Any help would be greatly
> appreciated. Thanks.
>
>
> For Each c In Worksheets("shift").Range(Cells(2, 2), Cells(lastRow,
> lastCol)).Cells
> If c.Value = "" Then c.Value = 0
> Next
>
> ' here I am setting each empty cell to zero


Not sure why you bother. An empty cell is actually marginally safer
since you don't get the stupid error message with log Y scales.
>
> Charts.Add
> ActiveChart.Location Where:=xlLocationAsObject, Name:="shift"
> ActiveChart.ChartType = xlXYScatter
> ChartOne = ActiveChart.Parent.Name
> **Worksheets("shift").ActiveChart.SetSourceData Source:=Worksheets
> ("shift").Range(Cells(2, 2), Cells(lastRow, lastCol)), _
> PlotBy:=xlColumns**
>
> ' here is where the code errors
>
> ActiveChart.PlotArea.Select
> Selection.Interior.ColorIndex = xlNone
> With Selection.Border
> .ColorIndex = 16
> .Weight = xlThin
> .LineStyle = xlContinuous
> End With


This looks like the result of record macro capture. Unfortunately not
everything works as advertised. And in XL2007 almost nothing does

Questions:
What are the values of lastRow, lastCol?
Running what version of Excel ?
Does it still fail if you step through it line by line in the debugger?

XL2007 is littered with race conditions where charts will not allow
selection of sub-objects until they have been fully instantiated and
initialised. This creates additional delays. Workarounds are documented.

I found this sequence to be least prone to race conditions YMMV

Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets(sheetname).Range(s), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.PlotArea.Interior.Color = RGB(255, 255, 255)

Regards,
Martin Brown
 
Reply With Quote
 
Mike Middleton
Guest
Posts: n/a
 
      14th Apr 2010
frostkiller -

An excellent source of information about using VBA for Excel charts is Jon
Peltier's pages:

http://peltiertech.com/Excel/Charts/chartvba.html

- Mike
http://www.MikeMiddleton.com



"frostkiller" <(E-Mail Removed)> wrote in message
news:111D00C8-7EA2-43A7-BC82-(E-Mail Removed)...
> Hi all,
>
> I am having trouble with my chart making macros. I am trying to create a
> series XY-scatter plot of several columns (in this particular case 13
> columns). My code if giving me an error, see code below between the double
> asterisk highlight **...**
>
> Do I need to plot each series at a time? Any help would be greatly
> appreciated. Thanks.
>
>
> For Each c In Worksheets("shift").Range(Cells(2, 2), Cells(lastRow,
> lastCol)).Cells
> If c.Value = "" Then c.Value = 0
> Next
>
> ' here I am setting each empty cell to zero
>
> Charts.Add
> ActiveChart.Location Where:=xlLocationAsObject, Name:="shift"
> ActiveChart.ChartType = xlXYScatter
> ChartOne = ActiveChart.Parent.Name
> **Worksheets("shift").ActiveChart.SetSourceData Source:=Worksheets
> ("shift").Range(Cells(2, 2), Cells(lastRow, lastCol)), _
> PlotBy:=xlColumns**
>
> ' here is where the code errors
>
> ActiveChart.PlotArea.Select
> Selection.Interior.ColorIndex = xlNone
> With Selection.Border
> .ColorIndex = 16
> .Weight = xlThin
> .LineStyle = xlContinuous
> End With


 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      16th Apr 2010
Here's one problem (there may be others):

Worksheets("shift").ActiveChart.SetSourceData

A worksheet doesn't have an active chart. Just use ActiveChart.SetSourceData

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


On 4/14/2010 2:26 PM, frostkiller wrote:
> Hi all,
>
> I am having trouble with my chart making macros. I am trying to create a
> series XY-scatter plot of several columns (in this particular case 13
> columns). My code if giving me an error, see code below between the double
> asterisk highlight **...**
>
> Do I need to plot each series at a time? Any help would be greatly
> appreciated. Thanks.
>
>
> For Each c In Worksheets("shift").Range(Cells(2, 2), Cells(lastRow,
> lastCol)).Cells
> If c.Value = "" Then c.Value = 0
> Next
>
> ' here I am setting each empty cell to zero
>
> Charts.Add
> ActiveChart.Location Where:=xlLocationAsObject, Name:="shift"
> ActiveChart.ChartType = xlXYScatter
> ChartOne = ActiveChart.Parent.Name
> **Worksheets("shift").ActiveChart.SetSourceData Source:=Worksheets
> ("shift").Range(Cells(2, 2), Cells(lastRow, lastCol)), _
> PlotBy:=xlColumns**
>
> ' here is where the code errors
>
> ActiveChart.PlotArea.Select
> Selection.Interior.ColorIndex = xlNone
> With Selection.Border
> .ColorIndex = 16
> .Weight = xlThin
> .LineStyle = xlContinuous
> End With

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plotting 3 column data as mutiple xy scatter plot lines on same graph Mahurshi Akilla Microsoft Excel Misc 0 10th Apr 2008 07:17 PM
Is there any one in the world who can help me in plotting data from grid to scatter chart in MSchart Amit Microsoft VB .NET 2 20th Oct 2007 08:06 AM
Scatter plot with two data series having common x-values =?Utf-8?B?R29yZG9u?= Microsoft Excel Charting 2 3rd Oct 2007 08:36 PM
chart data series -- plot a table as a single series =?Utf-8?B?aGpj?= Microsoft Excel Charting 7 20th Sep 2005 05:52 PM
Plotting multiple data series in a chart with Chart Wizard - HOW? Jack Lamberton Microsoft Access Reports 1 15th Dec 2003 07:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:02 PM.