Chart - call to MinimumScale function makes the plot disappear

MarieBocc

New Member
Joined
Jun 28, 2019
Messages
33
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 :

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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You don't appear to be setting the XValues for the chart series anywhere. I suggest you add that in.
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,539
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top