1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Option Explicit
Sub CreationTcd()
Dim ShSource As Worksheet, ShTcd As Worksheet
Dim I As Long, LigneDeTitre As Long, DerniereLigne As Long, DerniereColonne As Long
Dim AireTcd As Range
Dim Pvt As PivotTable
On Error GoTo FinCreationTcd
Set ShSource = Sheets("Schedule")
Set ShTcd = Sheets("Horizon_Planification")
With ShSource
LigneDeTitre = 1
DerniereColonne = .Cells(LigneDeTitre, .Columns.Count).End(xlToLeft).Column
DerniereLigne = .Cells(.Rows.Count, 1).End(xlUp).Row
Set AireTcd = .Range(.Cells(LigneDeTitre, 1), .Cells(DerniereLigne, DerniereColonne))
End With
If ShTcd.PivotTables.Count > 0 Then
With ShTcd
For I = .PivotTables.Count To 1 Step -1
.PivotTables(I).TableRange2.Delete
Next I
End With
End If
With ActiveWorkbook
.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=AireTcd, Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:=ShTcd.Cells(8, 1), TableName:="TCD1", DefaultVersion:=xlPivotTableVersion10
.ShowPivotTableFieldList = True
End With
Set Pvt = ShTcd.PivotTables("TCD1")
With Pvt
With .PivotFields("Flux")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Planification_Horizon")
.Orientation = xlPageField
.Position = 2
End With
.AddDataField .PivotFields("CONFIRMED"), "Nombre de CONFIRMED", xlCount
With .PivotFields("CONFIRMED")
.Orientation = xlPageField
.Position = 3
End With
With .PivotFields("Gestionnaire")
.Orientation = xlRowField
.Position = 1
End With
End With
GoTo FinCreationTcd
FinCreationTcd:
Set ShTcd = Nothing
Set Pvt = Nothing
Set AireTcd = Nothing
Set ShSource = Nothing
End Sub |
Partager