How to duplicate a series in the MS Excel chart?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oleval
    New Member
    • Feb 2008
    • 1

    How to duplicate a series in the MS Excel chart?

    Hi All,

    I need a VBA MS Excel code to duplicate a series in the chart, which has just one series. Effectively, as a result the chart should have two identical serieses.

    Thank you for your help!

    PS. I tried this code, but it ends up with run-time error...

    ActiveChart.Cha rtArea.Select ' the chart has one series
    ActiveChart.Ser iesCollection.N ewSeries
    ActiveChart.Ser iesCollection(2 ).Values = ActiveChart.Ser iesCollection(1 ).Values
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by oleval
    Hi All,

    I need a VBA MS Excel code to duplicate a series in the chart, which has just one series. Effectively, as a result the chart should have two identical serieses.

    Thank you for your help!

    PS. I tried this code, but it ends up with run-time error...

    ActiveChart.Cha rtArea.Select ' the chart has one series
    ActiveChart.Ser iesCollection.N ewSeries
    ActiveChart.Ser iesCollection(2 ).Values = ActiveChart.Ser iesCollection(1 ).Values
    the error might be because the chart is not selected when you run this code, and there's no ActiveChart. So you can select the chart before running or write a line to reference the desired chart, something like

    [CODE=vb]Workbooks("theB ooksName").work sheets("theShee tsName").charto bjects("theChar tsName").activa te[/CODE]

    of course you can skip the Workbooks part, and replace the worksheets part with ActiveWorksheet , but once again you'll have to be sure to have the right book and sheet selected.

    The name of the chart is put by Excel, it should be something like "Chart01" or "Chart02" or something like that. To know it, use the macro recorder. Select anything but the chart, and then select the chart and stop recording. When you see the recorded code, you'll see the chart's name in a line quite similar to the one i've just write above.

    HTH

    Comment

    Working...