Hello friends, I am trying to construct a pivot table, but once I run the code for pivotcache creation and seeing results in immediate window creates an error 1004 for the second time run of the code.
I am trying to seek an answer that can help me clear the cache in the starting of the pivot table, and construct a new one as I write the code.
Please help
I already tried:
1. activeworkbook.pivotcache.delete (doesnt work)
2.missingitems
I am trying to seek an answer that can help me clear the cache in the starting of the pivot table, and construct a new one as I write the code.
Please help
I already tried:
1. activeworkbook.pivotcache.delete (doesnt work)
2.missingitems
VBA Code:
Sub pivot1()
Dim sh As Worksheet
Dim shnew As Worksheet
Set sh = ActiveWorkbook.Sheets("Sheet1")
Set shnew = ActiveWorkbook.Sheets("Sheet2")
Debug.Print ActiveWorkbook.PivotCaches.Count
Debug.Print ActiveWorkbook.PivotTables.Count
sh.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table1", Version:=6).CreatePivotTable TableDestination:=shnew.Range("a3"), _
TableName:="PivotT1", DefaultVersion:=6
Debug.Print ActiveWorkbook.PivotCaches.Count
End Sub