Sub TCD()
'
' tcd Macro
'
Dim TCD As PivotTable
With Sheets("tcd")
If .PivotTables.Count > 1 Then .PivotTables(1).TableRange2.Delete
Set TCD = .PivotTableWizard(xlDatabase, Sheets("stat").Range("A1").CurrentRegion, .Range("A1"))
End With
With ActiveSheet.PivotTables("TCD").PivotFields("tg_nat")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("TCD").AddDataField ActiveSheet. _
PivotTables("TCD").PivotFields("tg_nat"), _
"Nombre de tg_nat", xlCount
ActiveSheet.PivotTables("TCD").PivotFields( _
"Nombre de tg_nat").Caption = "Occurences"
ActiveSheet.PivotTables("TCD").AddDataField ActiveSheet. _
PivotTables("TCD").PivotFields("tg_nat"), _
"Nombre de tg_nat", xlCount
With ActiveSheet.PivotTables("TCD").PivotFields( _
"Nombre de tg_nat")
.Caption = "Cumul"
.Calculation = xlPercentRunningTotal
.BaseField = "tg_nat"
.NumberFormat = "0,00%"
End With
With ActiveSheet.PivotTables("TCD").PivotFields("Cumul")
.NumberFormat = "0%"
End With
ActiveSheet.PivotTables("TCD").AddDataField ActiveSheet. _
PivotTables("TCD").PivotFields("Q_compenser"), _
"Nombre de Q_compenser", xlCount
With ActiveSheet.PivotTables("TCD").PivotFields( _
"Nombre de Q_compenser")
.Caption = "Min de Q_compenser"
.Function = xlMin
End With
Range("B6").Select
ActiveSheet.PivotTables("TCD").PivotFields("tg_nat"). _
AutoSort xlDescending, "Occurences", ActiveSheet.PivotTables( _
"TCD").PivotColumnAxis.PivotLines(1), 1
End Sub