Titre d'un graphique
i
Bonjour,
j'ai un souci avec mon code VBA, j'ai 3 feuille dans lesquels j'ai 1 ou plusieurs graphiques et le code (que je met à la fin) fonctionne très bien, mais je sais pas pourquoi sur une de mes feuilles la macro ne fonctionne pas
si je laisse "ActiveChart.ApplyLayout (1) " alors la Excel plante complètement et redémarre
si a la place je mets "ActiveChart.HasTitle = True "
quand je veux renommé mon titre j'ai un message d'erreur que me dit que mon graphique n'a pas de titre
es que quelqu'un aurait une idée ?
édit- j'ai oublié une info utile, en pas à pas la macro fonctionne très bien
Mon code qui plante :
Sub Affich_Graphique2()
ActiveSheet.Shapes.AddChart.Select
While ActiveChart.SeriesCollection.Count <> 0
ActiveChart.SeriesCollection(1).Delete
Wend
ActiveChart.SetSourceData Source:=Range("$C$2:$D$" & Range("a65536").End(xlUp).Row)
ActiveChart.ChartType = xlPie
ActiveChart.ApplyLayout (1)
'ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Characters.Text = nom_1
With ActiveSheet.ChartObjects(1)
.Left = Range("g2:l16").Left
.Top = Range("g2:l16").Top
.Width = Range("g2:l16").Width
.Height = Range("g2:l16").Height
End With
nom = ActiveSheet.Name
Sheets("Feuil3").Activate
Sheets(nom).Activate
End Suble code qui focntionne :
Sub Affich_Graphique1()
ActiveSheet.Shapes.AddChart.Select
While ActiveChart.SeriesCollection.Count <> 0
ActiveChart.SeriesCollection(1).Delete
Wend
i = 2
Do While i <= Range("a65536").End(xlUp).Row
With ActiveChart
.SeriesCollection.NewSeries
With .SeriesCollection(.SeriesCollection.Count)
.Name = Range("b" & i).Value 'Nom de la série
.XValues = 1
.Values = Range("e" & i)
End With
End With
i = i + 1
Loop
ActiveChart.ChartType = xlColumnClustered
ActiveChart.ApplyLayout (1)
If typedefaut = "D" Then
ActiveChart.ChartTitle.Text = "nom1"
ElseIf typedefaut = "V" Then
ActiveChart.ChartTitle.Text = "nom2"
ElseIf typedefaut = "F" Then
ActiveChart.ChartTitle.Text = "nom3"
End If
For Each co In ActiveChart.SeriesCollection
co.ApplyDataLabels
Next
ActiveSheet.Shapes.AddChart.Select
While ActiveChart.SeriesCollection.Count <> 0
ActiveChart.SeriesCollection(1).Delete
Wend
i = 2
Do While i <= Range("a65536").End(xlUp).Row
With ActiveChart
.SeriesCollection.NewSeries
With .SeriesCollection(.SeriesCollection.Count)
.Name = Range("b" & i).Value 'Nom de la série
.XValues = 1
.Values = Range("f" & i)
End With
End With
i = i + 1
Loop
ActiveChart.ChartType = xlColumnClustered
ActiveChart.ApplyLayout (1)
If typedefaut = "D" Then
ActiveChart.ChartTitle.Text = "nom10"
ElseIf typedefaut = "V" Then
ActiveChart.ChartTitle.Text = "nom20"
ElseIf typedefaut = "F" Then
ActiveChart.ChartTitle.Text = "nom30"
End If
For Each co In ActiveChart.SeriesCollection
co.ApplyDataLabels
Next
With ActiveSheet.ChartObjects(1)
.Left = Range("g2:l16").Left
.Top = Range("g2:l16").Top
.Width = Range("g2:l16").Width
.Height = Range("g2:l16").Height
End With
With ActiveSheet.ChartObjects(2)
.Left = Range("n2:s16").Left
.Top = Range("n2:s16").Top
.Width = Range("n2:s16").Width
.Height = Range("n2:s16").Height
End With
nom = ActiveSheet.Name
Sheets("Feuil3").Activate
Sheets(nom).Activate
End Sub