Hello everyone,
I am curently trying to create a chart with VBA and I am facing some dificulties trying to figure out how to adjust my X-axis. I use dates on this axis and if I do'nt set its the min and max dates programatically, the plot just goes from 01/01/1900 to 19/02/1900. The thing is, calling the MinimumScale function in my vba code indeed allows me to get the axis scale I wish for, but it removes the plot that was put there beforehand !
(The range C11:T11 contains the numbers of people required at the dates stated in C5:T5 and I just want to be able to reprensent it with a line chart.)
The code goes like this :
Does anyone know what I should do to get both the plot and the scale the way I want it ?
Thank you for reading,
Marie
I am curently trying to create a chart with VBA and I am facing some dificulties trying to figure out how to adjust my X-axis. I use dates on this axis and if I do'nt set its the min and max dates programatically, the plot just goes from 01/01/1900 to 19/02/1900. The thing is, calling the MinimumScale function in my vba code indeed allows me to get the axis scale I wish for, but it removes the plot that was put there beforehand !
(The range C11:T11 contains the numbers of people required at the dates stated in C5:T5 and I just want to be able to reprensent it with a line chart.)
The code goes like this :
Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Macro1()
Dim cht As Object
Set cht = ActiveSheet.ChartObjects.Add(Left:=10, Width:=1000, Top:=400, Height:=300)
With cht.Chart
.Type = xlLine
.SetSourceData Source:=Sheets("Filtres").Range("C11:T11")
.Location Where:=xlLocationAsObject, Name:="Filtres"
.HasTitle = True
.ChartTitle.Characters.Text = "Calendar repartition"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
.Axes(xlCategory, xlPrimary).CategoryType = xlTimeScale
.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "dd-mm-yyyy"
[COLOR=#ff0000].Axes(xlCategory, xlPrimary).MinimumScale = Sheets("Filtres").Cells(5, 3)[/COLOR]
.Axes(xlCategory, xlPrimary).MaximumScale = Sheets("Filtres").Cells(5, 20)
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Effectifs"
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
.HasDataTable = False
End With
ActiveChart.Axes(xlCategory).TickMarkSpacing = 7
End Sub[/FONT]
Does anyone know what I should do to get both the plot and the scale the way I want it ?
Thank you for reading,
Marie