Sub TEST()
Set Maplage = Range("A1").CurrentRegion
Maplage.Name = "TCD"
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"TCD").CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable5", DefaultVersion:=xlPivotTableVersion10
Sheets("Sheet4").Select
Cells(3, 1).Select
Dim p As PivotItem
Application.ScreenUpdating = False
With ActiveSheet.PivotTables("PivotTable5").PivotFields("VendorVname")
For Each p In .PivotItems
p.Visible = True
Next p
For Each p In .PivotItems
If p.Value <> "Didier" And p.Value <> "Robert" And .VisibleItems.Count > 1 Then p.Visible = False
Next p
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Facture")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("Montant"), "Count of Montant", xlCount
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of Montant")
.Caption = "Sum of Montant"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Compte")
.Orientation = xlColumnField
.Position = 1
End With
End Sub