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
|
Private Sub Worksheet_Change(ByVal Target As Range)
Dim PT As PivotTable 'pointeur vers le TCD
Dim p As PivotItem 'un item d'un champ du TCD
Dim strGrandeurs As String 'liste des grandeurs selectionnees
Dim strUsines As String 'liste des usines selectionnees
Dim strPVT As String 'liste des PVT selectionnes
Dim titreGCD As String 'titre du GCD
Dim toto As String
toto = Target.AddressLocal
If (Target.AddressLocal = "$C$1") Then
strGrandeurs = ""
strUsines = ""
strPVT = ""
Set PT = ActiveSheet.PivotTables("TCD1")
'recuperation des grandeurs selectionnees
For Each p In PT.PivotFields("Grandeur").PivotItems
If (p.Visible = True) Then strGrandeurs = IIf(strGrandeurs = "", p.Name, strGrandeurs & " + " & p.Name)
Next p
'recuperation des usines selectionnees
For Each p In PT.PivotFields("Usine").PivotItems
If (p.Visible = True) Then strUsines = IIf(strUsines = "", p.Name, strUsines & " + " & p.Name)
Next p
'recuperation des PVT selectionnes
For Each p In PT.PivotFields("PVT").PivotItems
If (p.Visible = True) Then strPVT = IIf(strPVT = "", p.Name, strPVT & " + " & p.Name)
Next p
'mise en place du titre sur le GCD
titreGCD = ""
If (strGrandeurs <> "") Then titreGCD = strGrandeurs
If (strUsines <> "") Then titreGCD = IIf(titreGCD <> "", titreGCD & ", " & strUsines, strUsines)
If (strPVT <> "") Then titreGCD = IIf(titreGCD <> "", titreGCD & ", " & strPVT, strPVT)
ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.SetElement (msoElementChartTitleCenteredOverlay)
ActiveChart.ChartTitle.Text = titreGCD
End If
End Sub |
Partager