Chart & Visualization Issues

How to Set an Excel Chart Axis Maximum from a Cell Value

Bushra ParveenBushra Parveen Nov 2, 2026 870 views

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.

How to Set an Excel Chart Axis Maximum from a Cell Value Automatically
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

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.

2
Select the Calculate Event

In the code window, select 'Worksheet' from the left drop-down menu and 'Calculate' from the right drop-down menu.

3
Enter the Macro Code

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).

4
Test the Chart

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 the Worksheet_Calculate Event
Chart Indexing: If you have multiple charts on the sheet, 'ChartObjects(1)' targets the first one. If your chart is different, refer to it by name, such as Me.ChartObjects("Chart 2").
Advanced Charting with WPS Spreadsheet

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. 1. Open Your Workbook: Launch WPS Spreadsheet and open the file containing your dynamic chart.
  2. 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. 3. Apply the Worksheet Event: Double-click the target sheet, select the Worksheet_Calculate event, and input your axis-scaling macro code.
  4. 4. Save and Execute: Save your document as an xlsm file. Modify your data to watch the chart update automatically in WPS.
Fully compatible with Microsoft Excel (.xlsx and .xlsm) formats.Robust VBA environment for advanced chart and axis automation.Lightweight architecture handles complex recalculations smoothly.Familiar user interface makes workflow transition seamless and intuitive.
microsoft office alternative - wps office

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").