Changing a charts axis using VBA

dan03uk

New Member
Joined
Mar 17, 2009
Messages
33
I have currently written a macro for changing a charts axis linked to a cell but this needs me to run the macro for the effects to take place. Is there away that will change the axis automatically when the number in the reference cell is changed. Below is the macro I have written

Code:
Sub ChangeAxisScales()
    With ActiveSheet.ChartObjects("Chart 6").Chart

        ' Category (X) Axis
        With .Axes(xlCategory)
            .MaximumScale = ActiveSheet.Range("$B$4").Value
            .MinimumScale = Worksheets("Sheet2").Range("$A$2").Value
            .MajorUnit = Worksheets("Sheet2").Range("$A$3").Value
        End With

        ' Value (Y) Axis
        With .Axes(xlValue)
            .MaximumScale = ActiveSheet.Range("$B$3").Value
            .MinimumScale = Worksheets("sheet2").Range("$A$2").Value
            .MajorUnit = Worksheets("Sheet2").Range("$A$3").Value
        End With

    End With
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,195,632
Messages
6,010,791
Members
441,569
Latest member
PeggyLee

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
Top