Consulting

Results 1 to 6 of 6

Thread: Solved: Stop watch in excel which just displays minutes

  1. #1
    VBAX Regular
    Joined
    Sep 2012
    Posts
    17
    Location

    Solved: Stop watch in excel which just displays minutes

    Hi,

    What I would like to have is a stopwatch in excel which just displays minutes i.e. instead of 1 hour 30 min I want a macro to just show 90.

    On a different forum I was able to find the following macro:
    [vba]

    Dim SchedRecalc As Date, datStartTime As Date
    Sub RecalcTimer()
    Dim wbk As Workbook
    Dim ws As Worksheet
    Set wbk = ThisWorkbook
    Set ws = wbk.Sheets(1) ' <== Change the "1" to appropriate #
    'ws.Range("C3").Value = Format(Now, "dd-mmm-yy")
    ws.Range("C4").Value = Format(Now - datStartTime, "hh:mm:ss")
    Call SetTimer
    End Sub
    Sub SetTimer()
    If datStartTime = 0 Then datStartTime = Now
    SchedRecalc = Now + TimeValue("00:00:01")
    Application.OnTime SchedRecalc, "RecalcTimer"
    End Sub
    Sub StopTimer()
    On Error Resume Next
    Application.OnTime EarliestTime:=SchedRecalc, _
    Procedure:="RecalcTimer", _
    Schedule:=False
    End Sub
    Sub ResetTimer()
    datStartTime = 0
    End Sub

    [/vba]

    See attached spreadsheet which shows the buttons.

    The first problem is that it shows it in the hours minutes seconds format. Is there a way to get to just show the number of minutes which have past?

    Also if the timer is started and then stopped it seems that when the timer is restarted again it starts from excel's now time rather than the time at which the clock was initially.


    Any help on this would be much appreciated.

    Daniel
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Sep 2012
    Posts
    17
    Location
    Sorry didn't quite finish the sentence - I was meant to say:

    "Also if the timer is started and then stopped it seems that when the timer is restarted again it starts from excel's now time rather than the time at which the clock was initially stopped."

  3. #3
    First problem is fixed, but I'm not quite sure if this is what you're after with regard to the second problem.
    Dim SchedRecalc As Date, datStartTime As Date
    
    Sub RecalcTimer()
        ThisWorkbook.Sheets(1).Range("C4").Value = DateDiff("s", datStartTime, Now) \ 60
        SetTimer
    End Sub
    Sub SetTimer()
        If datStartTime = 0 Then datStartTime = Now
        SchedRecalc = Now + TimeValue("00:00:01")
        Application.OnTime SchedRecalc, "RecalcTimer"
    End Sub
    Sub StopTimer()
        datStartTime = Now
        On Error Resume Next
        Application.OnTime EarliestTime:=SchedRecalc, Procedure:="RecalcTimer", Schedule:=False
    End Sub
    Sub ResetTimer()
        datStartTime = 0
    End Sub

  4. #4
    VBAX Regular
    Joined
    Sep 2012
    Posts
    17
    Location
    Cheers for that.

  5. #5
    VBAX Regular
    Joined
    Sep 2012
    Posts
    17
    Location
    Another solution is to use a formula

    =TIMEVALUE(TEXT(C4,"[hh]:mm"))*24*60

  6. #6
    VBAX Regular
    Joined
    Sep 2012
    Posts
    17
    Location
    Just realised don't need the brackets round the hours or with your code then leave out the *24*60

Posting Permissions

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