Position Graphique VBA
Résolu
choco_ben
-
choco_ben -
choco_ben -
Voici mon problème :
Je souhaite mettre plusieurs graphiques sur une feuille Excel et ensuite les positionner comme je le souhaite. J'ai réussi comme je le souhaitais pour le premier mais lorsque je souhaite positionner le second, c'est le premier qui se déplace.
Je n'arrive pas à comprendre quel est le problème ...
Voici mon code :
'1er graphique
Range("A4:I4,A62:I62").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Fiche Agence").Range( _
"A4:I4,A62:I62"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Fiche Agence"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Période"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Chiffre d'affaires en €"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
'compte le nombre de graphiques dans la feuille
nbgraph = Sheets("Fiche Agence").ChartObjects.Count
'le nouveau graphique correspond à l'index le plus élevé
Sheets("Fiche Agence").ChartObjects(nbgraph).Name = "CA"
With Sheets("Fiche Agence").ChartObjects("CA")
.Left = Range("A79").Left
.Top = Range("A79").Top
End With
ActiveSheet.ChartObjects("CA").Activate
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
'2eme graphique
Range("A4:I4,A31:I31").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Fiche Agence").Range( _
"A4:I4,A31:I31"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Fiche Agence"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Période"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Chiffre d'affaires en €"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
'compte le nombre de graphiques dans la feuille
nbgraph = Sheets("Fiche Agence").ChartObjects.Count
'le nouveau graphique correspond à l'index le plus élevé
Sheets("Fiche Agence").ChartObjects(nbgraph).Name = "CA-Epargne"
With Sheets("Fiche Agence").ChartObjects("CA-Epargne")
.Left = Range("D79").Left
.Top = Range("D79").Top
End With
ActiveSheet.ChartObjects("CA-Epargne").Activate
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
Je souhaite mettre plusieurs graphiques sur une feuille Excel et ensuite les positionner comme je le souhaite. J'ai réussi comme je le souhaitais pour le premier mais lorsque je souhaite positionner le second, c'est le premier qui se déplace.
Je n'arrive pas à comprendre quel est le problème ...
Voici mon code :
'1er graphique
Range("A4:I4,A62:I62").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Fiche Agence").Range( _
"A4:I4,A62:I62"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Fiche Agence"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Période"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Chiffre d'affaires en €"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
'compte le nombre de graphiques dans la feuille
nbgraph = Sheets("Fiche Agence").ChartObjects.Count
'le nouveau graphique correspond à l'index le plus élevé
Sheets("Fiche Agence").ChartObjects(nbgraph).Name = "CA"
With Sheets("Fiche Agence").ChartObjects("CA")
.Left = Range("A79").Left
.Top = Range("A79").Top
End With
ActiveSheet.ChartObjects("CA").Activate
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
'2eme graphique
Range("A4:I4,A31:I31").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("Fiche Agence").Range( _
"A4:I4,A31:I31"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Fiche Agence"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Période"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Chiffre d'affaires en €"
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
'compte le nombre de graphiques dans la feuille
nbgraph = Sheets("Fiche Agence").ChartObjects.Count
'le nouveau graphique correspond à l'index le plus élevé
Sheets("Fiche Agence").ChartObjects(nbgraph).Name = "CA-Epargne"
With Sheets("Fiche Agence").ChartObjects("CA-Epargne")
.Left = Range("D79").Left
.Top = Range("D79").Top
End With
ActiveSheet.ChartObjects("CA-Epargne").Activate
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
.Alignment = xlCenter
.Offset = 100
.ReadingOrder = xlContext
.Orientation = 45
End With
A voir également:
- Position Graphique VBA
- Changer carte graphique - Guide
- Ma position - Guide
- Suivi position google - Guide
- Graphique sparkline - Guide
- Graphique camembert excel - Guide
2 réponses
Bonjour,
Tu ne doit pas positionner par rapport à une cellule mais avec des références aux bords de la feuille.
A+
L'expérience instruit plus sûrement que le conseil. (André Gide)
Si tu te cogne à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
Tu ne doit pas positionner par rapport à une cellule mais avec des références aux bords de la feuille.
ActiveSheet.Shapes("Graphique 1").Left = 100 ActiveSheet.Shapes("Graphique 1").Top = 20
A+
L'expérience instruit plus sûrement que le conseil. (André Gide)
Si tu te cogne à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
Mon problème est que lorsque j'execute le deuxième graphique, c'est le premier qui va dans la cellule D79 alors que ça devrait être le second ...