In my active sheet I have two Pivot table (PivotTable1 and PivotTable2) sometimes they could be more though. I am trying to add a chart for each PT in the active sheet. So far I came up with this code but it is giving me 4 charts 3 blank ones and a correct one if one of the PT is selected.
Sub CreateChart1()
Dim pivot As PivotTable, sh As Worksheet, nrp As Long
Set sh = ThisWorkbook.Sheets("Sheet1")
For nrp = 1 To sh.PivotTables.Count
Set pivot = ActiveSheet.PivotTables(nrp)
For Each pivot In sh.PivotTables
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=pivot.Parent.Name
Next pivot
Next nrp
End Sub
Can somebody explain to me what am I doing wrong?
Any help is appreciated.
Thanks
Nick.