Automatically Set Excel Scatter Chart Y-Axis Limits for Lap Times
Question details
Automatically adjust an Excel XY scatter chart’s Y-axis limits to fit selected drivers’ 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.
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.
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.
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.
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.
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
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.

Use Excel’s automatic Y-axis bounds
Use automatic scaling if the chart already plots only the selected drivers and exact cell-driven bounds are unnecessary.
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.

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.




