Sub Macrocouleurlegende Macro
numerotableau = 3
numerolegend = 1
'boucle do loop
Do While Cells(p, 5).Value <> ""
'la colonne de mon tableau « essences forestières » est parcourue tant qu’il n’y a pas de cellule vide
'si la valeur trouvée est Hêtre la couleur a appliqué dans la légende est colorindex 4
If Cells(numerotableau, 5).Value = "Hêtre" Then
ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(numerolegend).LegendKey.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
ActiveWindow.Visible = False
End If
'si la valeur trouvée est Chênes la couleur a appliqué dans la légende est Colorindex 6
If Cells(numerotableau, 5).Value = "Chênes" Then
ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(numerolegend).LegendKey.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ActiveWindow.Visible = False
End If
'il n’y a plus qu’a multiplier les IF THEN en fonction des essences qui peuvent être contenues dans le tableau
numerotableau = numerotableau + 1
numerolegend = numerolegend + 1
Loop
End sub