Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Colorier les séries d'un graphique

2 réponses
Avatar
Richard G.
Bonjour,

J'ai ce code VBA pour colorier diff=E9remment chaque s=E9rie de
graphiques que je cr=E9=E9 avec une macro :

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(1).Select
With Selection.Border
.Weight =3D xlThin
.LineStyle =3D xlAutomatic
End With
Selection.Shadow =3D False
With Selection.Interior
.ColorIndex =3D 37
.Pattern =3D xlSolid
End With
ActiveChart.SeriesCollection(1).Points(2).Select
With Selection.Border
.Weight =3D xlThin
.LineStyle =3D xlAutomatic
End With
Selection.Shadow =3D False
With Selection.Interior
.ColorIndex =3D 40
.Pattern =3D xlSolid
End With
ActiveChart.SeriesCollection(1).Points(3).Select
With Selection.Border
.Weight =3D xlThin
.LineStyle =3D xlAutomatic
End With
Selection.Shadow =3D False
With Selection.Interior
.ColorIndex =3D 15
.Pattern =3D xlSolid
End With


=E7a marche tr=E8s bien quand le graphique a trois s=E9ries. Mais s'il
n'en a que deux, =E7a bugge logiquement ici :
ActiveChart.SeriesCollection(1).Points(3).Select

XLS ne trouve pas la 3=E8me s=E9rie puisqu'elle n'existe pas.
On error goto next ne fonctionne pas.
J'avais pens=E9 =E0 :
For i=3D1 to n
avec
ActiveChart.SeriesCollection(1).Points(n).Select

Mais =E9videmment je voudrais colorier chaque s=E9rie dans une couleur
diff=E9rente.=20


Comment faire ?=20
Merci par avance.

A+

2 réponses

Avatar
lSteph
Bonjour,
de prim'abord
On error goto next ne fonctionne pas.
On error resume next


Mais à part cela un truc du genre:


Dim i&

For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
ActiveChart.SeriesCollection(1).Points(i).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
Select Case i
Case 1

.ColorIndex = 37

Case 2
.ColorIndex = 40
Case 3
.ColorIndex = 15

Case Else
ColorIndex = 18
End Select


.Pattern = xlSolid
End With
Next





Cordialement.

lSteph

Il se trouve que Richard G. a formulé :
Bonjour,

J'ai ce code VBA pour colorier différemment chaque série de
graphiques que je créé avec une macro :

ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
.ColorIndex = 37
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(1).Points(2).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(1).Points(3).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With


ça marche très bien quand le graphique a trois séries. Mais s'il
n'en a que deux, ça bugge logiquement ici :
ActiveChart.SeriesCollection(1).Points(3).Select

XLS ne trouve pas la 3ème série puisqu'elle n'existe pas.
On error goto next ne fonctionne pas.
J'avais pensé à :
For i=1 to n
avec
ActiveChart.SeriesCollection(1).Points(n).Select

Mais évidemment je voudrais colorier chaque série dans une couleur
différente.


Comment faire ?
Merci par avance.

A+


--
- -

Avatar
Richard G.
Merci lSteph

Cela fonctionne très bien.

A+