Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing charts with VBA (2003)

    Hi,

    I am using a drop down to select departments on cell B2 of an excel sheet, on update it changes the chart series name and values. The problem I have is when I change the drop down the chart adds the new series names and values but retains the old series although it does rename them to series3, series 4 etc where the number is the first number after the series names added by the vba on change event.

    I have been messing about with the following bits of code and getting no where, any help would be great.

    ActiveChart.SeriesCollection(1).Delete only works if the object exsits, I was trying to creat some sort of count then loop that number of times. I no the following wont work but to give an idea what I'm trying to achieve.

    Dim i As Integar
    For i = 1 to ActiveChart.SeriesCollection.Count
    ActiveChart.SeriesCollection(1).Delete
    Next i

    Many thanks
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Changing charts with VBA (2003)

    If you want to delete series, you must loop backwards:

    Dim i As Integer
    For i = ActiveChart.SeriesCollection.Count To 1 Step -1
    ActiveChart.SeriesCollection(i).Delete
    Next i

Posting Permissions

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