Consulting

Results 1 to 2 of 2

Thread: STOPWATCH

  1. #1
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location

    Stopwatch

    I have seen many different types of scripts for developing a stopwatch in excel. To sum it up, using the below script, where can I insert a command designating a specific cell or range or cells to stop the timer. Commencing the timer is fine, but i find that when i begin typing the timer stops, hence the reason for wanting the specific cell designation. Thanks

    [vba]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[/vba]
    Last edited by Aussiebear; 08-17-2010 at 10:35 PM. Reason: Placed tags around code

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi.

    Well that is impossible to read. Put some code tags around the code and maybe someone will look at it!
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •