Why won't this work?: update graph's year VBA

Solved/Closed
Trowa - Apr 13, 2010 at 09:08 AM
 Trowa - Apr 19, 2010 at 08:38 AM
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 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 13, 2010 at 11:00 AM
possible to put up the book WITH graph ?
0
Of course Rizvisa, here is the book WITH graph:

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

Best regards,
Trowa
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 16, 2010 at 08:42 AM
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)
0
Thanks Rizvisa, works like a charm!

Best regards,
Trowa
0