Create an Excel Stopwatch and Log Times with VBA
Question details
Create a running stopwatch in Excel and record elapsed times in a worksheet.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user wants to start a stopwatch and log elapsed times using a worksheet control or another action.
- Observed behavior
- A stopwatch displays elapsed time and adds each recorded result to a worksheet log.
Use a desktop version of Excel that supports VBA, save the workbook as an Excel Macro-Enabled Workbook (.xlsm), and enable macros only if you trust the file. If the Developer tab is hidden, enable it in Excel's ribbon customization settings.
Build a Stopwatch and Time Log with Excel VBA
Use a VBA module and worksheet buttons to display elapsed time and add timestamped entries to a log.
This example updates the display about once per second. It measures elapsed time using the computer's clock, so changes to that clock can affect the result.
The running timer and accumulated time are held in VBA memory. Stop the timer before closing the workbook; reopening or resetting VBA does not restore the running session.
Add a worksheet and name it Stopwatch. The macro uses cell B1 for the display and columns A and B, starting at row 3, for the log.
Select Developer > Visual Basic, then choose Insert > Module in the VBA editor.
Paste the following code into the module: Option Explicit Private startedAt As Date Private accumulated As Double Private running As Boolean Private nextTick As Date Private Function ElapsedTime() As Double ElapsedTime = accumulated If running Then ElapsedTime = ElapsedTime + (Now - startedAt) End Function Private Function TickProcedure() As String TickProcedure = "'" & Replace(ThisWorkbook.Name, "'", "''") & "'!StopwatchTick" End Function Public Sub StopwatchStart() Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("Stopwatch") ws.Range("A1").Value = "Elapsed time" ws.Range("A3").Value = "Recorded at" ws.Range("B3").Value = "Elapsed time" ws.Range("B1").NumberFormat = "[h]:mm:ss" If running Then Exit Sub startedAt = Now running = True StopwatchTick End Sub Public Sub StopwatchTick() If Not running Then Exit Sub ThisWorkbook.Worksheets("Stopwatch").Range("B1").Value = ElapsedTime() nextTick = Now + TimeSerial(0, 0, 1) Application.OnTime EarliestTime:=nextTick, Procedure:=TickProcedure() End Sub Public Sub StopwatchStop() If Not running Then Exit Sub accumulated = ElapsedTime() running = False On Error Resume Next Application.OnTime EarliestTime:=nextTick, Procedure:=TickProcedure(), Schedule:=False On Error GoTo 0 ThisWorkbook.Worksheets("Stopwatch").Range("B1").Value = accumulated End Sub Public Sub StopwatchReset() StopwatchStop accumulated = 0 With ThisWorkbook.Worksheets("Stopwatch").Range("B1") .NumberFormat = "[h]:mm:ss" .Value = 0 End With End Sub Public Sub StopwatchLog() Dim ws As Worksheet Dim logRow As Long Set ws = ThisWorkbook.Worksheets("Stopwatch") ws.Range("A3").Value = "Recorded at" ws.Range("B3").Value = "Elapsed time" logRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1 ws.Cells(logRow, 1).Value = Now ws.Cells(logRow, 1).NumberFormat = "yyyy-mm-dd hh:mm:ss" ws.Cells(logRow, 2).Value = ElapsedTime() ws.Cells(logRow, 2).NumberFormat = "[h]:mm:ss" End Sub
Return to the Stopwatch sheet, use Insert > Shapes to add four shapes, and label them Start, Stop, Reset, and Log. Right-click each shape, select Assign Macro, and assign StopwatchStart, StopwatchStop, StopwatchReset, and StopwatchLog respectively.
Click Start to begin, then click Log whenever you want to record an elapsed time. Click Stop to pause; Start resumes the accumulated time. Click Reset to return the display to zero without deleting the existing log.

Manage Time Logs with WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and move everyday time-log work to WPS Spreadsheet; Excel-specific VBA automation may require a supported WPS configuration and separate compatibility testing.

Frequently Asked Questions
How do I show the Developer tab in Excel?
Open Excel's ribbon customization settings and select Developer. On Windows, use File > Options > Customize Ribbon, then check Developer.
Why do I need to save the workbook as .xlsm?
The .xlsm format retains VBA macros. Use File > Save As and select Excel Macro-Enabled Workbook before closing the file.
Can I log a time while the stopwatch is still running?
Yes. Click the shape assigned to StopwatchLog. The macro adds the current timestamp and elapsed time to the next row without stopping the timer.
Does Reset delete previous log entries?
No. StopwatchReset stops the timer and sets the display to zero. Delete entries from the Stopwatch worksheet manually if you no longer need them.
Why aren't the stopwatch buttons running?
Check that macros are enabled for the trusted workbook, the sheet is named Stopwatch, and each shape is linked to the correct macro through right-click > Assign Macro. Excel for the web does not run VBA macros.




