Consulting

Results 1 to 4 of 4

Thread: Create a Stopwatch for time study

  1. #1
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    2
    Location

    Question Create a Stopwatch for time study

    Hello,

    I am trying to create a stopwatch that doesn't stop or reset unless I click on the cell that has the running time. With this stopwatch, the goal is to have the ability to click on any cell and copy and paste the time (though the stopwatch will continue counting). I am conducting a time study, and I a just want to create a simple, user-friendly set-up.

    Here is the code I have so far (I didn't create this code)

    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
    As of now, this code will start timing when you double click on a cell in column A (that you have inputted a value in). The time will then stop with you click any other cell..

    I don''t want the stopwatch to stop unless I click on the cell that is counting, and I want to have the ability to double click on any cell and be able to paste the time at that very instant.

    Can anyone help?

    Thanks

  2. #2
    what is in column 3?

  3. #3
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    2
    Location
    I believe that it is placed above so it may be referred to on line 33, column 13.
    I'm not sure if that's true though. I am new to vba, so I am just learning syntax

  4. #4
    no
    myTime = Target.Offset(, 2).Value
    gets a value from column 3 of the worksheet

Tags for this Thread

Posting Permissions

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