Sub Test_TCD_Simple_par_Macro()
Dim pt As PivotTable, Kohoutek, Pyragony%
Set pt = Creation_TCD(ActiveSheet.Cells(1).CurrentRegion, xlDatabase)
Kohoutek = Array(Array("ITEMS", 1, 1), Array("REFS", 1, 2))
Application.ScreenUpdating = False
For Pyragony = 0 To UBound(Kohoutek, 1)
With pt.PivotFields(Kohoutek(Pyragony)(0))
.Orientation = Kohoutek(Pyragony)(1)
.Position = Kohoutek(Pyragony)(2)
End With
Next
pt.AddDataField pt.PivotFields("PRIX"), "Somme de PRIX", xlSum
End Sub
Private Function Creation_TCD(ByRef srcData As Range, Bazinga As XlPivotTableSourceType) As PivotTable
Dim ptCache As PivotCache, TCD As PivotTable, F As Worksheet
Set ptCache = ThisWorkbook.PivotCaches.Create(SourceType:=Bazinga, SourceData:=srcData)
Set F = ThisWorkbook.Sheets.Add
Set TCD = ptCache.CreatePivotTable(TableDestination:=F.Cells(3, 1))
Set Creation_TCD = TCD
End Function