VBA code error

dan03uk

New Member
Joined
Mar 17, 2009
Messages
33
Need some help with this VBA code, I can't see why it doesn't work.

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Select Case Target.Address
    Case "$E$2"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlCategory) _
            .MaximumScale = Target.Value
    Case "$E$3"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlCategory) _
            .MinimumScale = Target.Value
    Case "$E$4"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlCategory) _
            .MajorUnit = Target.Value
    Case "$F$2"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlValue) _
            .MaximumScale = Target.Value
    Case "$F$3"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlValue) _
            .MinimumScale = Target.Value
    Case "$F$4"
        ActiveSheet.ChartObjects("Chart 2").Chart.Axes(xlValue) _
            .MajorUnit = Target.Value
    Case Else
End Select
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
In what way isn't it working?

The Workbook_SheetChange event applies to every sheet in the workbook. ActiveSheet can be replaced by Sh, which is passed as an argument to the procedure.

Is it the intention to monitor changes on every worksheet or just one? If the latter you should use the Worksheet_Change event procedure.
 
Upvote 0

dan03uk

New Member
Joined
Mar 17, 2009
Messages
33
Hi thanks fir the help. It only neeeds to be changed on the actuve sheet so I will give what you said ago.
 
Upvote 0

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
What sort of chart do you have? It needs to be XY(Scatter) to change the scaling on the category axis.
 
Upvote 0

dan03uk

New Member
Joined
Mar 17, 2009
Messages
33
Hi thanks so much for your help i got it working, I was using the wrong address for the chart.
 
Upvote 0

dan03uk

New Member
Joined
Mar 17, 2009
Messages
33
One more wuick question is there away of stoping it from linking to ever sheet as it currently changes the axis on all sheets.
 
Upvote 0

Forum statistics

Threads
1,190,957
Messages
5,983,835
Members
439,864
Latest member
qazxsw12

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