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
 
As I said before, if you want the code to apply to only one sheet use the Worksheet_Change event procedure on the appropriate sheet.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Thanks for the help. Sorry been a bit of an idiot and not reading what you said. Wright I have done what you said now and here is the code I have written, but it doesn't seem to be changing anything.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
    Case "$E$2"
        Sh.ChartObjects("Chart 3").Chart.Axes (xlCategory)
            .MaximumScale = Target.Value
    Case "$E$3"
        Sh.ChartObjects("Chart 3").Chart.Axes(xlCategory) _
            .MinimumScale = Target.Value
    Case "$E$4"
        Sh.ChartObjects("Chart 3").Chart.Axes(xlCategory) _
            .MajorUnit = Target.Value
    Case "$F$2"
        Sh.ChartObjects("Chart 3").Chart.Axes(xlValue) _
            .MaximumScale = Target.Value
    Case "$F$3"
        Sh.ChartObjects("Chart 3").Chart.Axes(xlValue) _
            .MinimumScale = Target.Value
    Case "$F$4"
        Sh.ChartObjects("Chart 3").Chart.Axes(xlValue) _
            .MajorUnit = Target.Value
    Case Else
End Select
End Sub
 
Upvote 0
What do you mean by "it doesn't seem to be changing anything"? It will change Chart 3 if the values in E2:E4 or F2:F4 are changed by the user, but now you have no Sh object so Sh should be Me.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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