Share via

replace chart series values vba

Anonymous
2012-11-27T12:28:52+00:00

Hello,

this creates a new series on a chart, the array feeding it is myarr(11,12). each column on the array is selected using index.

The problem I have is that everytime I select a new column (with i as variable), a new series is created.

I just want to able to replace the values in the existing  series without drawing new series*.*

Thanks

With Worksheets("Charts").ChartObjects("myChart").Chart.SeriesCollection.NewSeries

            .Values = Application.Index( myarr, 0, i )

            .XValues = Array(2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020)

            .Name = "Sun"           

End With

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2012-11-27T13:10:34+00:00

Instead of

With Worksheets("Charts").ChartObjects("myChart").Chart.SeriesCollection.NewSeries

use

With Worksheets("Charts").ChartObjects("myChart").Chart.SeriesCollection(1)

if you want to change the first chart series.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2012-11-27T14:36:22+00:00

    If you have already created the series, it has become the last series in the chart, so you can use

        With Worksheets("Charts").ChartObjects("myChart").Chart

            With .SeriesCollection(.SeriesCollection.Count)

                .Values = Application.Index( myarr, 0, i )

                .XValues = Array(2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020)

                .Name = "Sun"          

            End With

        End With

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-11-27T13:41:16+00:00

    thanks.

    have another question, if I was to create a NewSeries first and then change its values (Y), what  would be the best approach?

    Was this answer helpful?

    0 comments No comments