Skip to main content

How to create stopwatch in Excel worksheet?

Author: Xiaoyang Last Modified: 2025-04-15

If you need a stopwatch in your Excel worksheet, it can help you track the time it takes to complete tasks. Imagine having a Start, Stop, and Reset button to control the stopwatch, as shown in the screenshot below. Clicking the Start button begins the timer, the Stop button pauses it, and the Reset button clears the time. In this article, we will show you step-by-step how to create a simple yet functional stopwatch in Excel using VBA code.

A screenshot of an Excel worksheet with a stopwatch containing Start, Stop, and Reset buttons

Create a stopwatch with three buttons by using VBA code


 Create a stopwatch with three buttons by using VBA code

To create a stopwatch with three buttons, Start, Stop and Reset, please do with the following steps one by one.

Firstly, insert three command buttons.

1. Click "Developer" >" Insert" > "Command Button", see screenshot:

A screenshot showing the Developer tab in Excel with the Insert Command Button option highlighted

2. Then drag the mouse to draw a button, after inserting the button, you can change the button caption, please click "Developer" > "Properties", in the" Properties" dialog, enter the new caption "Start” for this button in the textbox beside the "Caption", see screenshots:

A screenshot showing the Developer tab in Excel with the Properties option highlighted Arrow A screenshot of the Command Button properties dialog in Excel, showing where to set the Caption property to Start

3. Repeat the above two steps to insert other two buttons and caption them as “Stop” and “Reset”, see screenshot:

A screenshot of three Command Buttons being renamed to 'Start', 'Stop', and 'Reset'

4. After inserting the buttons, exit the design mode by clicking "Developer" > "Design Mode".

Secondly, create a VBA code.

5. And then, right click the current worksheet tab, and choose "View Code", in the popped out "Microsoft Visual Basic for Applications" window, please copy and paste the following code into the "Sheet Code":

Public StopIt As Boolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("C2") = 0 Then
  StartTime = Timer
  PauseTime = 0
  LastTime = 0
Else
  StartTime = 0
  PauseTime = Timer
End If
StartIt:
  DoEvents
  If StopIt = True Then
    LastTime = TotalTime
    Exit Sub
  Else
    FinishTime = Timer
    TotalTime = FinishTime - StartTime + LastTime - PauseTime
    TTime = TotalTime * 100
    HM = TTime Mod 100
    TTime = TTime \ 100
    hh = TTime \ 3600
    TTime = TTime Mod 3600
    MM = TTime \ 60
    SS = TTime Mod 60
    Range("C2").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
    If ResetIt = True Then
      Range("C2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
      LastTime = 0
      PauseTime = 0
      End
    End If
    GoTo StartIt
  End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  StopIt = True
End Sub
Private Sub CommandButton3_Click()
  Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
  LastTime = 0
  ResetIt = True
End Sub

A screenshot of the VBA editor with code for a stopwatch in Excel

Note: In the above code, "C2" is the cell where the stopwatch time will be inserted, and the "CommandButton1", "CommandButton2", "CommandButton3" are the button names, you can view the exact button name from the "Name Box", see screenshot:

A screenshot showing the Name Box in Excel used to verify the names of buttons added to the worksheet

Thirdly, format the stopwatch time cell.

6. Then you should format the time cell as "Text" format, and you can change the cell size, font, font color, background, etc. as you need, see screenshot:

A screenshot showing how to format a cell for stopwatch time in Excel, including font and background customization

7. After finishing above steps, from now on, when you click "Start" button, the time will start, and when you click the "Stop" button, it will stop time. The "Reset" button will reset the time, see screenshot:

A screenshot of a stopwatch running in an Excel worksheet with Start, Stop, and Reset buttons in action


Demo: Create a stopwatch with three buttons by using VBA code

 
Kutools for Excel: Over 300 handy tools at your fingertips! Enjoy permanently free AI features! Download Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!