How to Set an Excel Chart Axis Maximum from a Cell Value
Question details
The user needs a way to automatically update the maximum value of an Excel XY chart's x-axis based on a dynamically changing formula result in a specific worksheet cell.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A dynamic charting dashboard or report where the axis scale needs to expand or contract automatically as formula-driven data changes.
- Observed behavior
- Excel does not offer a native, non-VBA way to link an axis bounds to a cell reference. Furthermore, using standard VBA Worksheet_Change events fails to trigger the update when the target cell's value changes via formula recalculation.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm), and verify the exact cell reference containing your maximum axis value before adding the VBA code.
Use the Worksheet_Calculate Event
Implement a VBA macro using the Worksheet_Calculate event, which reliably triggers whenever formulas update their values, ensuring the chart reflects the new axis maximum immediately.
Because the reference cell contains a formula, standard Worksheet_Change triggers will not detect the value change. The Worksheet_Calculate event is the ideal solution because it listens for any formula recalculation on the sheet.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. In the Project Explorer on the left, double-click the name of the worksheet that contains your chart.
In the code window, select 'Worksheet' from the left drop-down menu and 'Calculate' from the right drop-down menu.
Type the following code inside the event block: Me.ChartObjects(1).Chart.Axes(xlCategory).MaximumScale = Range("D2").Value (Replace 'D2' with your actual formula cell).
Close the VBA editor and change the data feeding into your formula cell. The chart's x-axis maximum will automatically update upon recalculation.

Use Worksheet_Change to Monitor Input Ranges
If you have numerous formulas and Worksheet_Calculate causes performance drops, you can monitor the direct input cells that feed into the formula instead.
Easily Manage Dynamic Charts in WPS Office
WPS Spreadsheet provides powerful data visualization tools and comprehensive VBA/Macro support, allowing you to easily automate chart axis adjustments based on cell values without sacrificing speed.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open the file containing your dynamic chart.
- 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on 'Visual Basic Editor' to access the macro environment.
- 3. Apply the Worksheet Event: Double-click the target sheet, select the Worksheet_Calculate event, and input your axis-scaling macro code.
- 4. Save and Execute: Save your document as an xlsm file. Modify your data to watch the chart update automatically in WPS.

Frequently Asked Questions
Can I link a chart axis to a cell value without using VBA?
Currently, Microsoft Excel does not natively support linking chart axis minimums or maximums directly to cell references via the format pane. Using a brief VBA macro is the only reliable method to achieve automated scaling.
Why didn't my chart update when the formula changed?
If you used the Worksheet_Change VBA event, it only listens for manual data entry or external links. Formula recalculations do not trigger it. You must use the Worksheet_Calculate event to detect formula updates.
How do I update the Y-axis instead of the X-axis?
To update the vertical (Y) axis, change the VBA code from 'Axes(xlCategory)' to 'Axes(xlValue)'. For example: Me.ChartObjects(1).Chart.Axes(xlValue).MaximumScale = Range("D2").Value.
How do I find the correct name or index of my chart?
Select the chart in your worksheet and look at the Name Box located to the left of the formula bar. It will display the chart's name, such as 'Chart 1' or 'ScatterChart'. You can then reference it using Me.ChartObjects("Chart 1").




