Hi, Nima,
if you recorded the macro and run it without deleting the Pivot Table that has been used for recording the macro will try to build a new PT under the very same name:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Graydon-TL!R1C1:R15507C17", Version:=xlPivotTableVersion14). _
CreatePivotTable TableDestination:="Sheet3!R1C1", TableName:="PivotTable4" _
, DefaultVersion:=xlPivotTableVersion14
As the range fopr the data may differ please try this piece of code instead where both Sheetname as well as Name of PT are passed to the code:
Sub Call_Build_PT()
PT_Build "Sheet4", "PT_Nima_4"
End Sub
Sub PT_Build(strTab_PT As String, strPT_Name As String)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:=Sheets("Graydon-TL").Range("A1").CurrentRegion.Address(ReferenceStyle:=xlR1C1), _
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="'" & strTab_PT & "'!R3C1", _
TableName:=strPT_Name, _
DefaultVersion:=xlPivotTableVersion14
End Sub
There must be a Sheet4 in your workbook and no PT called PT_Nima_4. If you want to run the code again, either delete the PT or pass a new name for it.
Ciao,
Holger
Bookmarks