Hi,
I have the below code which will create a pivot table. Now suppose my data gets updated and i want a new pivot table but in different sheet it gives me error with table destination (may be because the name is similar).
Also will the code be able to identify the source data.
Code
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R11637C6").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable3").AddFields RowFields:=Array("P", _
"CP", " NAME", " NO")
ActiveSheet.PivotTables("z").PivotFields("ages"). _
Orientation = xlDataField
Cells.Select
Cells.EntireColumn.AutoFit
Range("B4").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields("CP").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
Range("C4").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields(" NAME").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
Display More
Thanks,
Nattya