Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem creatting charts with VBA

In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this? I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 762
Default Problem creatting charts with VBA

TheWizEd -

Jon Peltier's web page, "Quick Excel Chart VBA Examples," might be useful,
at

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

Note that he uses ChartObjects.Add instead of Charts.Add to get more
"control."

- Mike
http://www.MikeMiddleton.com


"TheWizEd" wrote in message
...
In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this?
I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem creatting charts with VBA

Mike,

I'm not trying to embed a chart but create a chart sheet.

"Mike Middleton" wrote:

TheWizEd -

Jon Peltier's web page, "Quick Excel Chart VBA Examples," might be useful,
at

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

Note that he uses ChartObjects.Add instead of Charts.Add to get more
"control."

- Mike
http://www.MikeMiddleton.com


"TheWizEd" wrote in message
...
In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this?
I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem creatting charts with VBA

In Excel 2007 the Charts.Add seems to produce weird results. It seems as
though it isn't creating a new chart but copying the last chart and appending
series to it. Try this.

Option Explicit

Sub CreateCharts()
Dim i As Integer
Dim r As Range
Dim c As Chart
Dim s As Series

' Populate with some data
Set r = Worksheets("Sheet1").Range("A1")
For i = 0 To 4
r.Offset(i, 0) = i + 1
r.Offset(i, 1) = i * 10
r.Offset(i, 2) = 1.1 * r.Offset(i, 1)
r.Offset(i, 3) = 1.5 * r.Offset(i, 1)
r.Offset(i, 4) = 50 - (i * 10)
r.Offset(i, 5) = 1.1 * r.Offset(i, 4)
r.Offset(i, 6) = 1.5 * r.Offset(i, 4)
Next

Set c = Charts.Add
c.ChartType = xlXYScatterSmooth
c.PlotBy = xlColumns
MsgBox c.SeriesCollection.Count
For i = c.SeriesCollection.Count To 2 Step -1
c.SeriesCollection(i).Delete
Next
Set s = c.SeriesCollection(1)
s.Values = Range(r.Offset(0, 1), r.Offset(4, 1))
s.XValues = Range(r.Offset(0, 0), r.Offset(4, 0))
Set c = Charts.Add
c.ChartType = xlXYScatterSmooth
c.PlotBy = xlColumns
MsgBox c.SeriesCollection.Count
Set s = c.SeriesCollection(1)
s.Values = Range(r.Offset(0, 2), r.Offset(4, 2))
s.XValues = Range(r.Offset(0, 0), r.Offset(4, 0))

End Sub


"TheWizEd" wrote:

Mike,

I'm not trying to embed a chart but create a chart sheet.

"Mike Middleton" wrote:

TheWizEd -

Jon Peltier's web page, "Quick Excel Chart VBA Examples," might be useful,
at

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

Note that he uses ChartObjects.Add instead of Charts.Add to get more
"control."

- Mike
http://www.MikeMiddleton.com


"TheWizEd" wrote in message
...
In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this?
I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem creatting charts with VBA

I think there is something wrong with Excel 2007. Trying to creat charts
through VBA, Excel will crash with error code 80010108. "Automation error.
The object invoked has disconnected from its clients."

I've been programming with Excel VBA for years and have never encountered
such a fatal error.

"TheWizEd" wrote:

In Excel 2007 the Charts.Add seems to produce weird results. It seems as
though it isn't creating a new chart but copying the last chart and appending
series to it. Try this.

Option Explicit

Sub CreateCharts()
Dim i As Integer
Dim r As Range
Dim c As Chart
Dim s As Series

' Populate with some data
Set r = Worksheets("Sheet1").Range("A1")
For i = 0 To 4
r.Offset(i, 0) = i + 1
r.Offset(i, 1) = i * 10
r.Offset(i, 2) = 1.1 * r.Offset(i, 1)
r.Offset(i, 3) = 1.5 * r.Offset(i, 1)
r.Offset(i, 4) = 50 - (i * 10)
r.Offset(i, 5) = 1.1 * r.Offset(i, 4)
r.Offset(i, 6) = 1.5 * r.Offset(i, 4)
Next

Set c = Charts.Add
c.ChartType = xlXYScatterSmooth
c.PlotBy = xlColumns
MsgBox c.SeriesCollection.Count
For i = c.SeriesCollection.Count To 2 Step -1
c.SeriesCollection(i).Delete
Next
Set s = c.SeriesCollection(1)
s.Values = Range(r.Offset(0, 1), r.Offset(4, 1))
s.XValues = Range(r.Offset(0, 0), r.Offset(4, 0))
Set c = Charts.Add
c.ChartType = xlXYScatterSmooth
c.PlotBy = xlColumns
MsgBox c.SeriesCollection.Count
Set s = c.SeriesCollection(1)
s.Values = Range(r.Offset(0, 2), r.Offset(4, 2))
s.XValues = Range(r.Offset(0, 0), r.Offset(4, 0))

End Sub


"TheWizEd" wrote:

Mike,

I'm not trying to embed a chart but create a chart sheet.

"Mike Middleton" wrote:

TheWizEd -

Jon Peltier's web page, "Quick Excel Chart VBA Examples," might be useful,
at

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

Note that he uses ChartObjects.Add instead of Charts.Add to get more
"control."

- Mike
http://www.MikeMiddleton.com


"TheWizEd" wrote in message
...
In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this?
I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Problem creatting charts with VBA

Well, through a lot of trial and error I figured a work around for the
SeriesCollection problem and the fatal Excel crash.

First regarding the crash, it turns out if the Excel tab is set to a chart
and you delete it through VBA, Excel crashes. In my subroutine that deletes
old charts I simply change the focus to a sheet first thats not being deleted.

Regarding the SeriesCollection I developed a subroutine that clears the
SeriesCollection and either returns the first series or creates a new one.
SeriesCollection of a new chart is unpredicable. Some times it starts with
one series, sometimes many and sometimes none.

Private Function GetNewSeries(cChart As Chart) As Series
Dim i As Integer
For i = cChart.SeriesCollection.Count To 2 Step -1
cChart.SeriesCollection(i).Delete
Next
If cChart.SeriesCollection.Count = 1 Then
Set GetNewSeries = cChart.SeriesCollection(1)
Else
Set GetNewSeries = cChart.SeriesCollection.NewSeries
End If
End Function


"TheWizEd" wrote:

In Excel 2007, when I create a new chart using Charts.Add I get a chart that
has all the series of a previously created chart. How can I prevent this? I
want a clean slate. I know that in the past I could not avoid having at
least one series when creating a chart. I simply redefine the attributes of
series one. And this seems to be true of 2007 as well.

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
Problem with charts nabil Charts and Charting in Excel 0 March 1st 09 07:27 PM
problem printing charts Brian Charts and Charting in Excel 2 May 16th 08 03:21 PM
Problem with charts ildivino Charts and Charting in Excel 6 July 26th 07 09:28 AM
problem with charts botha822[_7_] Excel Programming 0 August 9th 06 10:16 PM
Odd problem with charts... narrow! rci Excel Programming 0 December 9th 04 05:42 PM


All times are GMT +1. The time now is 01:29 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"