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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Option Explicit
Dim wsData As Worksheet, wsPT As Worksheet
Dim rngData As Range
Dim ptCache As PivotCache
Dim pt As PivotTable
Sub TCDautomatique3_Bouton2_Cliquer()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set wsData = Worksheets("Données3")
Set rngData = wsData.Cells(1).CurrentRegion
Set wsPT = Worksheets("TCD automatique3")
'Suppression de tous les TCD existants dans la feuille
For Each pt In wsPT.PivotTables
pt.TableRange2.Clear
Next pt
With wsPT
Set ptCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, rngData, 4)
Set pt = ptCache.CreatePivotTable(wsPT.Range("B12"), "TCD_1", , 4)
With Sheets("TCD automatique3").Activate
Range("B10") = "Les salaires annuels bruts en kilo euros par type de formation "
Range("B10").Font.Size = 18
Range("B10").Font.Italic = True
Range("B10").Font.Name = "Arial"
End With
With pt
.ManualUpdate = True
'Ajout d'une Ligne Régime de formation
With .PivotFields("regime_6m")
.Orientation = xlRowField
.Position = 1
End With
'Ajout d'une Ligne spécialité
With .PivotFields("specialite_6m")
.Orientation = xlRowField
.Position = 2
End With
' Calcul du saliare moyen
With pt.PivotFields("emploi_salaire_6m")
.Orientation = xlDataField
.Function = xlAverage
.Position = 1
.NumberFormat = "0.00"
.Name = "Moyenne"
End With
'Calcul du salaire Min
With pt.PivotFields("emploi_salaire_6m")
.Orientation = xlDataField
.Function = xlMin
.Position = 2
.NumberFormat = "0.00"
.Name = "Min"
End With
' Calcul du salaire Max
With pt.PivotFields("emploi_salaire_6m")
.Orientation = xlDataField
.Function = xlMax
.Position = 3
.NumberFormat = "0.00"
.Name = "Max"
End With
' Calcul du salaire Median
With pt.PivotFields("emploi_salaire_6m")
.Orientation = xlDataField
.WorksheetFunction.Median ("emploi_salaire_6m")
.Position = 4
.NumberFormat = "0.00"
.Name = "Mediane"
End With
.ManualUpdate = False
End With
End With
Set pt = Nothing
Set ptCache = Nothing
Set rngData = Nothing
Set wsPT = Nothing: Set wsData = Nothing
End Sub |
Partager