Macro to Create a Pivot Table from New Pivot Cache
Sub Create_Pivot_Table_From_Cache()
Dim oPC As PivotCache
Dim oPT As PivotTable
Dim oWS As Worksheet
oWS = ActiveSheet
oPC = ActiveWorkbook.PivotCaches.Create(xlDatabase, oWS.UsedRange)
oPT = oPC.CreatePivotTable(oWS.[D20], "Pivot From Cache", True)
oPT.AddFields(oPT.PivotFields("Item").Name, oPT.PivotFields("Customer").Name)
oPT.AddDataField(oPT.PivotFields("Qty"), "Quantity", xlSum)
End Sub
PivotCache represents the collection of memory caches from the PivotTable reports in a workbook. Each memory cache is represented by a PivotCache object. The above example creates a pivotcache from existing data and then using the cache a pivot table is created
See also:
Create Additional Pivot Table using Excel VBA (from Existing PivotCache)
Create Pivot Table using Excel VBA
Create Pivot Table from VBA using Wizard