Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrXIT
Application.EnableEvents = False
If Not (Intersect(Target, Range("d39:e39")) Is Nothing) Then
With Target.Parent.ChartObjects(1).Axes(xlCategory)
If Range("d39").Value <> "" Then .MinimumScale = Range("d39").Value
If Range("e39").Value <> "" Then .MaximumScale = Range("e39").Value
End With
ElseIf Not (Intersect(Target, Range("h39:i39")) Is Nothing) Then
With Target.Parent.ChartObjects(1).Axes(xlValue)
If Range("h39").Value <> "" Then .MinimumScale = Range("h39").Value
If Range("i39").Value <> "" Then .MaximumScale = Range("i39").Value
End With
End If
ErrXIT:
Application.EnableEvents = True
End Sub
Option Explicit
Sub doOneParam(whatParam, whatVal)
If whatVal <> "" Then whatParam = whatVal
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrXIT
Application.EnableEvents = False
With Target.Parent.ChartObjects(1)
Select Case Target.Address(False, False, xlA1)
Case "d39": doOneParam .Axes(xlCategory).MinimumScale, Target.Value
Case "e39": doOneParam .Axes(xlCategory).MaximumScale, Target.Value
Case "h39": doOneParam .Axes(xlValue).MinimumScale, Target.Value
Case "i39": doOneParam .Axes(xlValue).MaximumScale, Target.Value
End Select
End With
ErrXIT:
Application.EnableEvents = True
End Sub
you could automate this by putting some code like this in the Worksheet_Change event. In this example the x-axis of a chart named "Chart 1" will be scaled to whatever the user enters into cells G2 and H2
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("G2") Or Target = Range("H2") Then
ActiveSheet.ChartObjects("Chart 1").Activate
With ActiveChart.Axes(xlCategory)
If Range("G2").Value <> "" Then .MinimumScale = Range("G2").Value
If Range("H2").Value <> "" Then .MaximumScale = Range("H2").Value
End With
End If
End Sub
if you don't know what your chart name is, try replacing the chart name with an index number, ActiveSheet.ChartObjects(1).Activate