Proposition
Function nbGraph()
nbGraph = ActiveSheet.ChartObjects.Count
End Function
Function nbSeries(obj As Object)
On Error GoTo fin:
i = 0
With obj
Do
i = i + 1
.FullSeriesCollection(i).Select
Loop
End With
fin:
nbSeries = i - 1
End Function
Sub couleur(iGraph As Integer, iSerie As Integer, R, G, B)
If iGraph > nbGraph Then MsgBox "Le graphique """ & iGraph & """ n'existe pas !": Exit Sub
ActiveSheet.ChartObjects(iGraph).Activate
If iSerie > nbSeries(ActiveChart) Then MsgBox "La série """ & iSerie & """ n'existe pas !": Exit Sub
ActiveChart.FullSeriesCollection(iSerie).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(R, G, B)
.Transparency = 0
.Solid
End With
End Sub
et
Sub mise_en_couleur()
Dim i As Integer, j As Integer
indic = Array("CHT", "WMD", "CMD", "GMD", "TMD", "APTMD")
col = Array(2, 12, 22, 32, 42, 52)
quelIndic = ""
With ActiveWorkbook.SlicerCaches("Segment_Indicateurs3")
For i = 1 To .SlicerItems.Count
If .SlicerItems(i).Selected Then
quelIndic = .SlicerItems(i).Caption
For j = 0 To UBound(indic)
If quelIndic = indic(j) Then
Exit For
End If
Next
Exit For
End If
Next i
End With
ActiveSheet.ChartObjects(1).Activate
For i = 1 To nbSeries(ActiveChart)
couleur 1, i, Range("AD" & col(j) + i - 1), Range("AE" & col(j) + i - 1), Range("AF" & col(j) + i - 1)
Next
ActiveSheet.ChartObjects(1).Select
End Sub