Consulting

Results 1 to 12 of 12

Thread: Stopwatch

  1. #1

    Stopwatch

    Hi,

    I am a new user and hope you guys can help me with my Excel problem.

    I have inserted a stopwatch into my spreadsheet from an excellent article I found on this site.

    However, I have a couple of problems.....

    Firstly, whenever I change another cell in a different worksheet in the same book, the stopwatch stops working. I need the stopwatch to carry on as I simultaneously change cells in other worksheets.

    Also, is it possible to create a total stopwatch timer no matter how many times I stop & start the stopwatch?

    Many thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post the code, we are not mind readers.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Sorry! This is the code:

    [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]
    Thanks!


  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Location
    Cincinnati, OH
    Posts
    86
    Location
    Hi Baraon. What precision are you looking for? Is seconds enough? I have some ready code, but the precision is in milliseconds. I suppose it would be easy enough to adapt to seconds. A doevents loop as above might not be a good choice...

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This may be pretty cute, but it is darn inefficient, hogging the processor as it does.

    If you don't need that level of granularity, that is one second intervals being good enough, you could do better using OnTime.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    I actually only need one minute intervals. Currently, I am just converting the seconds on stopwatch into minutes in another cell.

    Any code you have that would sort my problem and increase efficiency would be much appreciated.

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Baron
    When you post code, use the green VBA button to format it as shown.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is an example.

    It hsa two independent counters, they can be started, stopped at will, independently. You can configure the intervals to be different if you wish, the setting is in the code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    That's great xld!

    However, I am having trouble copying the code into my spreadsheet.

    When I try to run the macro it comes up with an error message which highlights this line:

    Worksheets(1).Range("TimerCell1").Value = nCounter1

    Could you possibly explain what I need to do to get it to work in my spreadsheet?

    Thanks.

  10. #10
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Could you possibly explain what I need to do to get it to work in my spreadsheet?
    [VBA]Worksheets(1).Range("TimerCell1").Value = nCounter1[/VBA]

    Have you setup a named range named TimerCell1 in your workbook?
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  11. #11
    Right, I have done that...but now I have this message instead in ThisWorkbook (Code):

    Worksheets(1).Range("TimerCell1").Value = ""

    Thanks.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post your workbook.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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