Easy VB question

pagrender

Well-known Member
Joined
Sep 3, 2008
Messages
652
Hi everyone,

Here's an easy question for someone... how do I convert this code to a Worksheet Change Event?

Sub ChangeAxisScales()
With ActiveSheet.ChartObjects("AllDataChart").Chart

' Value (Y) Axis
With .Axes(xlValue)
.MaximumScale = ActiveSheet.Range("$G$2").Value
.MinimumScale = ActiveSheet.Range("$G$3").Value
.MajorUnit = ActiveSheet.Range("$G$4").Value
End With
End With
End Sub

Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe this on the sheet level?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With ActiveSheet.ChartObjects("AllDataChart").Chart
    With .Axes(xlValue)
        If Target.Address = "$G$2" Then .MaximumScale = Target.Value
        If Target.Address = "$G$3" Then .MinimumScale = Target.Value
        If Target.Address = "$G$4" Then .MajorUnit = Target.Value
    End With
End With
End Sub
 
Upvote 0
Just to verify...

When you say "on the sheet level", does that mean to right click on the tab name, choose view code, and paste the code into VB?
 
Upvote 0

Forum statistics

Threads
1,216,096
Messages
6,128,809
Members
449,468
Latest member
AGreen17

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