VBA & Macro Problems

Create an Excel Stopwatch That Records Elapsed Time Using VBA

Maira MehtabMaira Mehtab Oct 22, 2026 871 views

Question details

The user needs to create a stopwatch within a spreadsheet that records elapsed time in a cell when a key is pressed, while allowing the timer to continue running in the background.

How to Create an Excel Stopwatch That Records Elapsed Time
Product
Excel
Device & OS
not provided
Scenario
Tracking task durations or logging multiple time intervals during an ongoing event directly in a spreadsheet.
Observed behavior
Excel does not have a native built-in stopwatch feature. Users cannot automatically track running time or capture elapsed intervals without utilizing custom VBA automation.
Before you start

Ensure you have the Developer tab enabled in your spreadsheet application and remember to save your file as a Macro-Enabled Workbook (.xlsm) to allow VBA code execution.

Solution 1Recommended

Create a Custom Stopwatch using VBA Macro

Use VBA's Application.OnTime method to build a continuous stopwatch that records elapsed time into specific cells on command.

Since Excel lacks a built-in stopwatch, you must write a VBA macro that continuously schedules itself to update a cell every second.

This method utilizes the Application.OnTime command to run a background timer, and separate macro subroutines to start, log the elapsed time, and stop the timer.

1
Enable the Developer Tab

Click File in the top ribbon, navigate to Options, and select Customize Ribbon. Check the box next to 'Developer' in the right pane and click OK.

2
Open the VBA Editor

Navigate to the Developer tab and click 'Visual Basic', or simply press Alt + F11 on your keyboard to launch the VBA Editor.

3
Insert a New Module

In the left-hand Project Explorer pane, right-click on your workbook name, select Insert, and then click Module to create a blank script window.

4
Write the Stopwatch Code

Define your variables for start time and elapsed time. Create a 'StartTimer' subroutine that records the current time using the Now() function, and use Application.OnTime to schedule an 'UpdateTimer' macro that continuously refreshes the elapsed time in a designated cell.

5
Assign Macros to Worksheet Buttons

Go back to your worksheet, click Insert > Shapes, and draw a button. Right-click the shape, click Assign Macro, and select your 'StartTimer' macro. Repeat this process to create 'Log Time' and 'Stop Timer' buttons.

Create a Custom Stopwatch using VBA Macro
VBA Execution Pauses During Cell Editing: Keep in mind that the timer will pause if you enter 'Edit Mode' (e.g., double-clicking a cell or typing inside it). It will resume executing the Application.OnTime queue once you press Enter.
Automate with WPS Office

Build Your Spreadsheet Stopwatch with WPS Office

WPS Spreadsheet provides excellent support for VBA macros, allowing you to create custom stopwatches and automate complex workflows just as seamlessly as in Microsoft Excel.

  1. 1. Download and Install WPS Office: Download WPS Office and open WPS Spreadsheet.
  2. 2. Access the VBA Editor: Navigate to the Developer tab and click on 'VBA Editor' to open the scripting environment.
  3. 3. Paste and Run Your Macro: Insert a module, paste your stopwatch code, and seamlessly assign the macros to buttons within your spreadsheet.
Full support for VBA macros and the Application.OnTime method100% compatible with Microsoft Excel (.xlsx and .xlsm) macro formatsLightweight architecture ensures background macros run smoothly without freezing the UI
QA img-9

Frequently Asked Questions

Why does the stopwatch stop running when I edit a cell?

Spreadsheet applications process user interface actions on a single thread. When you enter cell edit mode, all background VBA macros, including Application.OnTime, are temporarily suspended until you press Enter or click away.

Can I use this VBA stopwatch on web-based spreadsheet versions?

No, web versions of spreadsheet software do not support VBA macros. You must use desktop applications like WPS Office or desktop Excel to execute VBA-based stopwatches.

How do I save a workbook that contains a VBA stopwatch?

You must save the file in a Macro-Enabled Workbook format (.xlsm). If you accidentally save it as a standard .xlsx file, the VBA stopwatch code will be permanently removed.