I have multiple pivot charts each with their own pivot table on separate worksheets in Excel 2002.
When I try to generate these charts with VBA with the following code:
Set cht = Charts.Add(After:=Worksheets("Setup"))
With cht
' we use named ranges here
.SetSourceData Source:=range(tblName)
.Name = chtName
....
where tblName is a named range just created a few lines before, the code runs fine if there is only one table and chart generate but gives me a run time error 1004: "The source data of a PivotChart report cannot be changed..." if I try to generate pivot table and chart set one after another.
Going to Insert -> Name -> Define, the list of named ranges created seems to be correct.
What is the correct way of setting the source data for a pivot chart with a dynamic range?