Why won't this work?: update graph's year VBA [Solved/Closed]

Report
-
 Trowa -
Hi,

My graph has a timeline of one year. After that year the timeline needs to be updated.
To get the current year I have used the functions TODAY() and YEAR().
The function YEAR() is in cell A35 of the same sheet as the graph.
Then I used the following code to update the graph's year:
Sub JaarUpdateGrafiek()
    Sheets("Grafiek").Select
    ActiveSheet.ChartObjects("Grafiek 1").Activate
    With ActiveChart.Axes(xlCategory)
        .MinimumScale = "1-1-" & Range("A35").Value
        .MaximumScale = "31-12-" & Range("A35").Value
        .CrossesAt = "1-1-" & Range("A35").Value
    End With
End Sub

The MinimumScale updates correctly, but for some reason the code gets stuck on .MaximumScale?!
The following error message is displayed (sorry for the bad translation):
Error 1004 during execution:
Property MaximumScale of class Axis can't be initiated.

Why does my method work for .MinimumScale but not for .MaximumScale???

Best regards,
Trowa

3 replies

Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
756
possible to put up the book WITH graph ?
Of course Rizvisa, here is the book WITH graph:

https://authentification.site/files/21968938/Copy_of_PostPlanning.xls

Best regards,
Trowa
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
756
Hi Trowa

Try this

.MinimumScale = CDate("1-1-" & Range("A35").Value)
.MaximumScale = CDate("31-12-" & Range("A35").Value)
.CrossesAt = CDate("1-1-" & Range("A35").Value)
Thanks Rizvisa, works like a charm!

Best regards,
Trowa