It worked for me ...
Sub Sample()
Dim pt As PivotTable
Sheets.Add.Name = "Pivot"
With ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=Sheets("DATA").Cells(1, 1).CurrentRegion)
Set pt = .CreatePivotTable(TableDestination:="Pivot!R3C1")
End With
'~~> Rest of Code
End Sub
Or if you want to do it your own way,
Sub Sample()
Dim pt As PivotTable
Dim Pcache As PivotCache
Sheets.Add.Name = "Pivot"
Set Pcache = ActiveWorkbook.PivotCaches.Create(xlDatabase, _
Sheets("DATA").Cells(1, 1).CurrentRegion)
Set pt = Pcache.CreatePivotTable(tabledestination:=("Pivot!R3C1"))
'~~> Rest of the code
End Sub
Caution: If the PIVOT sheet exists, you will receive an error message. Maybe you would like to add this to your code?
Application.DisplayAlerts = False
On Error Resume Next
Sheets("Pivot").Delete
On Error GoTo 0
Application.DisplayAlerts = True
Sheets.Add.Name = "Pivot"
source
share