Sub Macro2_générique()
Dim sht As Worksheet, pvt As PivotTable, pvtCache As PivotCache, sTableau$, NomTCD$
X = Int(Rnd * 100000) + Second(Time)
NomTCD = InputBox("Nom du TCD?", "Test", "_TCD_" & X)
'Attention: il faut sélectionner le tableau initial
sTableau = Selection.Parent.Name & "!" & Selection.Address(ReferenceStyle:=xlR1C1)
Set pvtCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlConsolidation, SourceData:=sTableau)
Set pvt = pvtCache.CreatePivotTable(TableDestination:="", TableName:=NomTCD)
pvt.DataPivotField.PivotItems("Nombre de Valeur").Position = 1
pvt.PivotFields("Colonne").Orientation = xlHidden
pvt.PivotFields("Ligne").Orientation = xlHidden
Range("A2").Select
Selection.ShowDetail = True
End Sub