VBA, créer une boucle qui s'arrete si une case est vide

hugo4777

XLDnaute Nouveau
Bonjour, je souhaiterais une aide de votre part.

Je vous explique mon problème, je débute sur VBA et j'essaye petit à petit de réaliser une macro qui réalise un graphique. J'arrive avec un code pas très beau à réaliser le graphique.
Mais, j'ai un nombre de série qui est variable. J'aimerais créer une boucle qui selon le nombre de variable me rajoute sur mon graphique les séries.

Mon nombre de série devient variable à partir de la cinquième série et ces séries seront des nuages de point

Je ne sais pas si c'est très clair, je vous met mon code ci-dessous

Et je vous remercie de vos réponses

VB:
Sub graphiqueok2()
ActiveCell.CurrentRegion.Name = "selection"
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("Feuil2").Range("Selection")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Feuil2"
    ActiveChart.SetSourceData Source:=Range("Selection")
    ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
    ActiveChart.FullSeriesCollection(1).AxisGroup = 1
    ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered
    ActiveChart.FullSeriesCollection(2).AxisGroup = 1
    ActiveChart.FullSeriesCollection(3).ChartType = xlLine
    ActiveChart.FullSeriesCollection(3).AxisGroup = 1
    ActiveChart.FullSeriesCollection(4).ChartType = xlLine
    ActiveChart.FullSeriesCollection(4).AxisGroup = 1
    ActiveChart.FullSeriesCollection(3).AxisGroup = 2
    ActiveChart.Parent.Height = 700
    ActiveChart.Parent.Width = 1500
    ActiveChart.Axes(xlCategory).MajorUnit = 3
    ActiveChart.Parent.Left = 100
    ActiveChart.Parent.Top = 100
    ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = 80
    ActiveChart.Axes(xlValue, xlPrimary).MaximumScale = 80
    ActiveChart.PlotArea.Format.Fill.ForeColor.Brightness = -0.1000000015
ActiveChart.Axes(xlCategory).TickLabels.Font.Name = "Times New Roman"
ActiveChart.Axes(xlValue, xlSecondary).TickLabels.Font.Name = "Times New Roman"
ActiveChart.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "Times New Roman"
ActiveChart.Axes(xlValue, xlSecondary).TickLabels.Font.Size = 9
ActiveChart.Axes(xlValue, xlPrimary).TickLabels.Font.Size = 9
ActiveChart.Axes(xlCategory).TickLabels.Font.Size = 8
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Caption = "mm water"
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Times New Roman"
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 10
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Top = 45
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Left = 45
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Orientation = xlHorizontal
ActiveChart.Axes(xlValue, xlSecondary).HasTitle = True
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Caption = "°C"
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Font.Name = "Times New Roman"
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Font.Size = 10
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Top = 45
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Left = 1370
ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Orientation = xlHorizontal
ActiveChart.Legend.Position = xlLegendPositionCorner
ActiveChart.Legend.Left = 1250
ActiveChart.Legend.Top = 120
ActiveChart.Legend.Width = 100
ActiveChart.Legend.Height = 100
ActiveChart.Legend.Font.Size = 9
ActiveChart.Legend.Format.Fill.Visible = msoTrue
ActiveChart.Legend.Format.Fill.ForeColor.ObjectThemeColor = msoThemeColorBackground1
ActiveChart.Legend.Format.Line.Visible = msoTrue
ActiveChart.Legend.Format.Line.ForeColor.ObjectThemeColor = msoThemeColorText1
ActiveChart.FullSeriesCollection(4).Format.Line.Weight = 2.25
ActiveChart.FullSeriesCollection(3).Format.Line.Weight = 2.25
ActiveChart.FullSeriesCollection(2).Format.Line.Weight = 0.75
ActiveChart.FullSeriesCollection(1).Format.Line.Weight = 0.75
ActiveChart.FullSeriesCollection(4).Format.Line.ForeColor.RGB = RGB(146, 208, 80)
ActiveChart.FullSeriesCollection(3).Format.Line.ForeColor.RGB = RGB(112, 48, 160)
ActiveChart.FullSeriesCollection(2).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
ActiveChart.FullSeriesCollection(1).Format.Line.ForeColor.RGB = RGB(160, 0, 0)
ActiveChart.FullSeriesCollection(5).AxisGroup = 1
ActiveChart.FullSeriesCollection(6).AxisGroup = 1
ActiveChart.FullSeriesCollection(5).ChartType = xlXYScatter
ActiveChart.FullSeriesCollection(6).ChartType = xlXYScatter
ActiveChart.FullSeriesCollection(6).HasDataLabels = True
ActiveChart.FullSeriesCollection(6).DataLabels.Position = xlLabelPositionAbove
ActiveChart.FullSeriesCollection(5).HasDataLabels = True
ActiveChart.FullSeriesCollection(5).DataLabels.Position = xlLabelPositionAbove
ActiveChart.FullSeriesCollection(7).HasDataLabels = True
ActiveChart.FullSeriesCollection(7).DataLabels.Position = xlLabelPositionAbove
End Sub
 

Discussions similaires

Réponses
0
Affichages
137

Statistiques des forums

Discussions
312 113
Messages
2 085 430
Membres
102 889
dernier inscrit
monsef JABBOUR