Set chart properties without selecting chart

davidam

Active Member
Joined
May 28, 2010
Messages
497
Office Version
  1. 2021
Platform
  1. Windows
Hi,
According to Microsoft documentation, I should be able to set the Axis.MinimumScale and AxisMaximumnScale properties as follows:
Code:
With Charts("Chart1").Axes(xlValue)
 .MinimumScale = 10  
.MaximumScale = 120  
End With
However, I cannot make this, or any permutation like it, work and I am forced to activate charts in order to set these properties.
I use:
Code:
    runSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).MinimumScale = runSheet.Range("P37").Value
    ActiveChart.Axes(xlValue).MaximumScale = runSheet.Range("O36").Value
    
    runSheet.ChartObjects("Chart 2").Activate
    ActiveChart.Axes(xlValue).MinimumScale = runSheet.Range("P37").Value
    ActiveChart.Axes(xlValue).MaximumScale = runSheet.Range("O36").Value

This really seems to slow things down. At the very least I would like to be able to speed this process up.
Thanks in advance
David
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try it this way . . .

VBA Code:
    With runSheet.ChartObjects("Chart 1").Chart
        .Axes(xlValue).MinimumScale = runSheet.Range("P37").Value
        .Axes(xlValue).MaximumScale = runSheet.Range("O36").Value
    End With

And the same thing for your other chart.

Hope this helps!
 
Upvote 0
Try it this way . . .

VBA Code:
    With runSheet.ChartObjects("Chart 1").Chart
        .Axes(xlValue).MinimumScale = runSheet.Range("P37").Value
        .Axes(xlValue).MaximumScale = runSheet.Range("O36").Value
    End With

And the same thing for your other chart.

Hope this helps!
Domenic,
That did the trick! Thanks so much!
I have not been on this great site for a while and is so nice to know that there is still great help available.
Happy New Year to All.
David
 
Upvote 0
You're very welcome, I'm glad I could help.

And Happy New Year to you too! :)
 
Upvote 0
Domenic,
That did the trick! Thanks so much!
I have not been on this great site for a while and is so nice to know that there is still great help available.
Happy New Year to All.
David
Therefore, I switched the marked solution post accordingly.

Happy New Year!
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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