Sub TCD_TEST()
Der = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row
For i = 2 To Der
If Range("A" & i).Interior.ColorIndex = 46 Then
Rows(i).Insert
Exit For
End If
Next
For j = 2 To Der
If Range("A" & j) = "" Then
Exit For
End If
Next
Dim Plg As Range, Nom_TCD
Set Plg = Feuil1.Range("A1:T" & j - 1)
Nom_TCD = InputBox("Nom du TCD?", "TCD", "TCD_N" & Second(Time))
ActiveWorkbook.PivotCaches.Add(SourceType:=1, _
SourceData:=Plg).CreatePivotTable TableDestination:="", _
TableName:=CStr(Nom_TCD), DefaultVersion:=1
With ActiveSheet
.PivotTableWizard TableDestination:=.Cells(1, 1)
With .PivotTables(CStr(Nom_TCD))
With .PivotFields("Division")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Article")
.Orientation = xlDataField
.Position = 1
End With
With .PivotFields("Mag.")
.Orientation = xlRowField
.Position = 2
End With
End With
End With
End Sub