Option Explicit
Public Sub Create_PT()
'Déclaration des variables
Dim wb As Workbook
Dim wsData As Worksheet
Dim PTCache As PivotCache
Dim pt As PivotTable
'Optimisation (gel affichage)
Application.ScreenUpdating = False
'Initialisation des variables
Set wb = ActiveWorkbook
Set wsData = wb.Worksheets("Matelas")
'Création cache (source des données)
Set PTCache = wb.PivotCaches.Create(xlDatabase, wsData.Cells(1).CurrentRegion)
'Création tableau croisé dynamique (TCD)
Set pt = PTCache.CreatePivotTable(wsData.Cells(1, 8), "TCD_1")
With pt
.ManualUpdate = True
'Code
'
'
.ManualUpdate = False
End With
'RAZ variables
Set pt = Nothing
Set PTCache = Nothing
Set wsData = Nothing
Set wb = Nothing
End Sub
dim A as Long,
dim Rng as range
a = [E65000].End(xlUp).Row
Set Rng = Range("E1:F" & a)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= Rng