Chart & Visualization Issues

Automatically Set Excel Scatter Chart Y-Axis Limits for Lap Times

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

Automatically adjust an Excel XY scatter chart’s Y-axis limits to fit selected drivers’ lap times.

Automatically Set Excel Scatter Chart Y-Axis Limits for Lap Times
Product
Microsoft Excel
Device & OS
not provided
Scenario
A scatter chart compares lap times for selected drivers, and the user wants a readable vertical scale as the selection changes.
Observed behavior
The desired chart bounds follow the minimum and maximum lap times for the selected drivers.
Before you start

Make sure lap times are numeric Excel time values, not text, and that the selected-driver list matches the drivers displayed in the chart. The formula-and-VBA method requires desktop Excel with FILTER support and macros enabled.

Solution 1Recommended

Set Y-axis bounds from selected lap times with formulas and VBA

Use this method when the chart needs explicit bounds that update from a selected-driver list.

This example assumes the chart and selection list are on the same worksheet. The formulas calculate the limits; VBA applies them to the chart because Excel does not directly link axis bounds to cells.

1
Prepare the data and selection

Select the lap-time data and choose Insert > Table. Name the table LapData on the Table Design tab, with columns named Driver and LapTime. Enter the selected driver names in F2:F10 on the chart worksheet, and ensure the chart displays those same drivers.

2
Calculate the limits

Enter =IFERROR(MIN(FILTER(LapData[LapTime],(COUNTIF($F$2:$F$10,LapData[Driver])>0)*(LapData[Driver]<>"")*ISNUMBER(LapData[LapTime]))),"") in G2. Enter =IFERROR(MAX(FILTER(LapData[LapTime],(COUNTIF($F$2:$F$10,LapData[Driver])>0)*(LapData[Driver]<>"")*ISNUMBER(LapData[LapTime]))),"") in G3.

3
Add the worksheet code

Right-click the chart worksheet tab, choose View Code, and paste this code into that worksheet’s code window: Private Sub Worksheet_Calculate() Dim lo As Double, hi As Double, pad As Double If Not IsNumeric(Me.Range("G2").Value) Or Not IsNumeric(Me.Range("G3").Value) Then Exit Sub If Me.Range("G2").Value = "" Or Me.Range("G3").Value = "" Then Exit Sub lo = CDbl(Me.Range("G2").Value) hi = CDbl(Me.Range("G3").Value) pad = Application.Max((hi - lo) * 0.02, 1 / 86400) On Error GoTo CleanUp Application.EnableEvents = False With Me.ChartObjects("Chart 1").Chart.Axes(xlValue) .MinimumScale = lo - pad .MaximumScale = hi + pad End With CleanUp: Application.EnableEvents = True End Sub

4
Match the chart name and save

Select the chart and check its name in Excel’s Name Box; replace Chart 1 in the code if needed. Choose File > Save As and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Enable macros when prompted, then change the names in F2:F10 to test the bounds.

Set Y-axis bounds from selected lap times with formulas and VBA
How updates work: The code runs when the worksheet recalculates and adds at least one second of padding on each side. If no numeric lap times match, the formulas return blanks and the existing axis bounds remain unchanged. Set Formulas > Calculation Options to Automatic so selection changes trigger recalculation.
Free Microsoft Office alternative

Explore lap-time scatter charts in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and Excel format compatibility, making it easy to open existing workbooks and continue chart analysis. The Excel VBA method above is specific to Excel and is not a guaranteed WPS macro solution.

Create and review XY scatter charts for lap-time analysisOpen and save Microsoft Excel formats, including XLSXWork in a familiar, easy-to-use spreadsheet interfaceMove existing spreadsheets into a lightweight Office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can I link Excel chart axis bounds directly to worksheet cells?

Excel’s Format Axis pane accepts fixed numbers or automatic bounds, not direct cell references. Use a worksheet calculation event and VBA to read the cells and set MinimumScale and MaximumScale.

Why does the axis stay unchanged when I select a driver?

Check that the driver name matches LapData[Driver], the lap times are numeric, macros are enabled, and Formulas > Calculation Options is set to Automatic. Also verify that the chart name in the worksheet code matches the actual chart name.

What happens if only one lap time matches?

The minimum and maximum are equal, but the VBA example adds at least one second of padding to each side so the chart still has a usable axis range.

Why does automatic scaling include values outside the lap-time range?

Excel may round automatic bounds or include zero for readability. For tighter, predictable limits, calculate the minimum and maximum in cells and apply them with the VBA method.