How to set the Y axis using VBA?? Help

Branagan_1

New Member
Joined
Apr 25, 2012
Messages
12
Hi,

I am not very good with VBA but, I'm trying to change the Y Axis to a value in a cell (basically i'm trying to tighten up the auto setting). I would also like it to only happen to a specific chart (Chart 45) every time the cell changes. I have managed to find some code that I think may work but I already have a worksheet_change event and I don't know how to combine the two... Code below...Any help would be great... Thanks in advace!


Current code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)


  If Target.Column = 5 And Target.Row = 241 Then
    RangeValue = "E233:H233"
    DrivingCell = "E241"
    GoTo FormatChange
  End If
    If Target.Column = 6 And Target.Row = 241 Then
    RangeValue = "K233:N233"
    DrivingCell = "F241"
    GoTo FormatChange
  End If
  If Target.Column = 7 And Target.Row = 241 Then
    RangeValue = "Q233:T233"
    DrivingCell = "G241"
    GoTo FormatChange
  End If
  If Target.Column = 8 And Target.Row = 241 Then
    RangeValue = "W233:Z233"
    DrivingCell = "H241"
    GoTo FormatChange
  End If
Exit Sub

FormatChange:
Application.ScreenUpdating = False
Range(RangeValue).Select
      Select Case Range(DrivingCell).Value
        Case "Vol"
            Selection.NumberFormat = "0,000"
        Case "Vol WSE"
            Selection.NumberFormat = "0,000"
        Case "SOM Share"
            Selection.NumberFormat = "0.0%"
        Case "SOM Share SE"
            Selection.NumberFormat = "0.0%"
        Case "SOM Share WSE"
            Selection.NumberFormat = "0.0%"
    End Select
Range(DrivingCell).Select
Application.ScreenUpdating = True


End Sub

Code I think will work
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
    Case "$A$1"
        ActiveSheet.ChartObjects("Chart 45").Chart.Axes(xlValue) _
            .MaximumScale = Target.Value
    Case "$A$2"
        ActiveSheet.ChartObjects("Chart 45").Chart.Axes(xlValue) _
            .MinimumScale = Target.Value
    Case "$A$3"
        ActiveSheet.ChartObjects("Chart 45").Chart.Axes(xlValue) _
            .MajorUnit = Target.Value
    Case Else
End Select
End Sub
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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