Changing Series Origin with VBA for excel

Franky Leonardo Prieto 1 Reputation point

I need to create several charts with different data but the same format, for a report.
I duplicate the first chart and change the location and the series origin but there are different behavior. Some times I can change the series origin with

ChartObject(n).Chart.SeriesCollection(1).Values = Range(range 1st serie).Address(, , , True)
ChartObject(n).Chart.SeriesCollection(2).Values = Range(range 2nd sere).Address(, , , True)

But sometimes when it changes the first one, it deletes the second one and it generates an error when it tryes to changes origin from a non-existing serie.

How I can know when change the origin from the both series, and when delete the second?

If this always happen, I could write:

ChartObjects(n).Chart.SeriesCollection(1).Values = Range(range 1st serie).Address(, , , True)
ChartObjects(n).Chart.SeriesCollection(2).Values = Range(range 2nd sere).Address(, , , True)

But sometimes it deletes, sometimes it doesn´t

What would be the best way to do this?

0 comments No comments
{count} votes