Help with VBA code to format Axes Xl Value based on Cell reference

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
886
Office Version
  1. 365
Platform
  1. Windows
I have a VBA code but a section of it I cannot seem to get to work. What I am trying to do is format the Axis Minimum Bound to a number referenced in Cell V1 and keep the Maximum as Auto.

Can anyone advise what I am doing wrong?

VBA Code:
     ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.Axes(xlValue).Select
    ' this line:
ActiveChart.Axes(xlValue).MinimumScale = ActiveSheet.Range("V1").Value
    Application.CommandBars("Format Object").Visible = False
    Application.CutCopyMode = False
    Range("A2").Select
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
VBA Code:
ActiveSheet.ChartObjects("Chart 3").Activate
With ActiveChart.Axes(xlValue)
    .MinimumScale = ActiveSheet.Range("V1").Value
End With
...
 
Upvote 0
I copied the first 3 lines of your code and used it on a chart of random data values between 20 and 200 I made for the testing. In V1, I changed the value to 0, 25, 40, etc. Every time, the code worked fine to change the minimum value. The min value, however, is not formula-based, so that when V1 changes, the code needs to be run again to reset.

The maximum value did change, though it was still set to Auto. This changing of the max value is reproduced when manually changing my min value in the Options window. No value in the chart is over 200, but when the min is 0, the auto max is 250; when min is 40, the max is 220.

What is it about your results that you find wrong?
 
Upvote 0
VBA Code:
ActiveSheet.ChartObjects("Chart 3").Activate
With ActiveChart.Axes(xlValue)
    .MinimumScale = ActiveSheet.Range("V1").Value
End With
...

I tried your code but for some reason it still did not use the value from V1 as the minimum value (see below screenshot)

1592834510906.png
 
Upvote 0
VBA Code:
ActiveSheet.ChartObjects("Chart 3").Activate
With ActiveChart.Axes(xlValue)
    .MinimumScale = ActiveSheet.Range("V1").Value
End With
...

Nevermind. The problem was where I put that section of code. I foolishly put it before I sorted. (feeling foolish ? )

Thank you very much for your guys help. The code works perfectly :giggle:
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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