Create an Excel Stopwatch That Records Elapsed Time Using VBA
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.

- 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.
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.
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.
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.
Navigate to the Developer tab and click 'Visual Basic', or simply press Alt + F11 on your keyboard to launch the VBA Editor.
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.
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.
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.

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. Download and Install WPS Office: Download WPS Office and open WPS Spreadsheet.
- 2. Access the VBA Editor: Navigate to the Developer tab and click on 'VBA Editor' to open the scripting environment.
- 3. Paste and Run Your Macro: Insert a module, paste your stopwatch code, and seamlessly assign the macros to buttons within your spreadsheet.

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.




