Excel

Create a StopWatch in Excel

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Zack Barresse

Description:

Be able to create a running stop watch in Excel. 

Discussion:

You may find a need sometimes to have a Stop Watch in Excel. You can set this for a specific cell or range of cell that when double click on, a Stop Watch will start and show you the time elapsed counting in a cell. 

Code:

instructions for use

			

Public stopMe As Boolean Public resetMe As Boolean Public myVal As Variant Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Target.Column = 1 Then If Target.Value = myVal And Target.Value <> "" Then 'Changed Dim startTime, finishTime, totalTime, timeRow startTime = Timer stopMe = False resetMe = False myTime = Target.Offset(, 2).Value Target.Offset(, 1).Select startMe: DoEvents timeRow = Target.Row finishTime = Timer totalTime = finishTime - startTime Target.Offset(, 1).Value = Format(myTime + totalTime, "0.0000") & " Seconds" If resetMe = True Then Target.Offset(, 1).Value = 0 Target.Offset(, 2).Value = 0 stopMe = True End If If Not stopMe = True Then Target.Offset(, 2).Value = totalTime GoTo startMe End If Cancel = True End Else 'Not Changed stopMe = True Cancel = True End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) myVal = Target.Value End Sub

How to use:

  1. Copy above code.
  2. In Excel press Alt + F11 to enter the VBE.
  3. Press Ctrl + R to show the Project Explorer.
  4. Double click the worksheet on the left you wish to add the code to.
  5. Paste code into the right pane.
  6. Press Alt + Q to close the VBE.
  7. Save workbook before any other changes.
 

Test the code:

  1. Enter a value in column A.
  2. Double click said value to start StopWatch.
  3. Double click said value while StopWatch is running to reset at specified (col C) interval.
  4. Double click a blank cell to stop SopWatch.
 

Sample File:

StopWatchEx.zip 9.15KB 

Approved by mdmackillop


This entry has been viewed 652 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express