Change the origin of the data of an existing Excel chart using VBA

0

I have an existing graphic, called GRAFICO_PARETO. This graph has a data origin, for example let's say from A1 to G20, and I have to change it for a different range, but not from the Excel front-end, but from vba. The code that I have tried is:

Dim datosGrafico As Range
Set datosGrafico = Range(Range("Z2"), Range("Z2").End(xlToRight).End(xlDown))

ActiveSheet.ChartObjects("GRAFICO_PARETO").Chart.SetSourceData Source:=datosGrafico

But the last line gives an error at run time.

I'm doing it in Microsoft Excel 2016 in Spanish. It does not have the same behavior as 2010, the answers should be about the 2016 version.

Thanks and best regards

.

    
asked by jusna 10.10.2018 в 14:57
source

0 answers