+ Reply to Thread
Results 1 to 2 of 2

Extra series in charts when created using vba

  1. #1
    JacksonRJones
    Guest

    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 Where:=xlLocationAsNewSheet
    With ActiveChart
    .HasTitle = False
    .Axes(xlCategory, xlPrimary).HasTitle = False
    .Axes(xlValue, xlPrimary).HasTitle = False
    End With


  2. #2
    Jon Peltier
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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 Where:=xlLocationAsNewSheet
    > With ActiveChart
    > .HasTitle = False
    > .Axes(xlCategory, xlPrimary).HasTitle = False
    > .Axes(xlValue, xlPrimary).HasTitle = False
    > End With
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1