Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Extra series in charts when created using vba

Hello. I am having trouble with charting from vba. I used the macro
recorder to generate code to creat charts, and am only trying to create a
single series. Sometimes additional series will show up on the chart, either
blank ones, or sometimes series with only yvalues. Any help would be greatly
appreciated. Here is the code I am using for the charts:

(i is an integer)

Dim xrng As Range
Dim yrng As Range

Set xrng = Worksheets("sheet1").Range("A5:A" & i - 1)
Set yrng = Worksheets("sheet1").Range("B5:B" & i - 1)

Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = xrng
ActiveChart.SeriesCollection(1).Values = yrng
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Extra series in charts when created using vba

The chart plots whatever data is in the current region of the active cell,
so you may start with several series.

To account for this, put a loop like this before adding any series:

Do Until ActiveChart.SeriesCollection.Count = 0
ActiveChart.SeriesCollection(1).Delete
Loop

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


"JacksonRJones" wrote in message
...
Hello. I am having trouble with charting from vba. I used the macro
recorder to generate code to creat charts, and am only trying to create a
single series. Sometimes additional series will show up on the chart,
either
blank ones, or sometimes series with only yvalues. Any help would be
greatly
appreciated. Here is the code I am using for the charts:

(i is an integer)

Dim xrng As Range
Dim yrng As Range

Set xrng = Worksheets("sheet1").Range("A5:A" & i - 1)
Set yrng = Worksheets("sheet1").Range("B5:B" & i - 1)

Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = xrng
ActiveChart.SeriesCollection(1).Values = yrng
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With



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
xlStockVOHLC chart with extra xlColumnClustered series Amir Charts and Charting in Excel 0 February 11th 10 09:25 AM
A series created with data in two workbooks Andrew Charts and Charting in Excel 1 January 13th 10 11:56 PM
How do I delete an already created series of check boxes? Tony Excel Discussion (Misc queries) 2 July 5th 07 09:52 PM
Charts switch from 'Series in Rows' to 'Series in Columns' Peace Charts and Charting in Excel 4 March 22nd 07 03:52 AM
I've created a custom fill series. Now I don't know how to use i. candybluevt Excel Discussion (Misc queries) 2 January 26th 05 08:48 PM


All times are GMT +1. The time now is 10:01 PM.

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"