Setting Chart Axis Max & Min to Value on Worksheet

DTD

New Member
Joined
Mar 2, 2012
Messages
19
I want to set the minimum and maximum values for the values of a stacked bar chart's x-axis to the values specified by a pair of cells on the worksheet in which the chart is located.

X17 has the minimum value ~41000 since I'm displaying dates
X18 has the maximum value ~41500

I have the following in the Worksheet Change area in VBA for the Worksheet in question, but when I change a cell in the sheet, nothing happens. I know the code is running, since I can put a break in and it stops, but it doesn't have any effect on the chart.

The code will run no matter which cell is changed, and it shouldn't care what cell is changed, it will always be using X17 and X18 as inputs, and changing the min & max values accordingly, correct? So I can change cell A1 and it will set (or re-set) the axis max/min to these values?

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
    Case "$x$18"
        ActiveSheet.ChartObjects("Chart 4").Chart.Axes(xlCategory) _
            .MinimumScale = Target.Value
    Case "$x$17"
        ActiveSheet.ChartObjects("Chart 4").Chart.Axes(xlCategory) _
            .MaximumScale = Target.Value
    Case Else
End Select
End Sub

Thanks in advance for any assistance! This is my first attempt at using Select Case and Worksheet Change code

Dave
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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