+ Reply to Thread
Results 1 to 9 of 9

Can someone help me create a stopwatch?

Hybrid View

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Shreveport, Louisiana
    MS-Off Ver
    Excel 2011
    Posts
    7

    Can someone help me create a stopwatch?

    Hello.

    New to the forum. Good with excel but do am diving into new territory with macros and VBA.

    I would like to create a stop watch. I've been researching this topic on forum and the internet for days but am getting nowhere.

    Using Excel 2011 on a Mac, Lion 10.7.

    I'm tracking scene lengths in movies. For instance think of your favorite movie- the first scene is usually so many minutes long... scene two is so many minutes long and so on. I want to track these lengths scene by scene and elapsed.

    Example

    A1 would start and always be 00:00:00 (hh:mm:ss) It's the start of the movie.
    B1 would be the end of scene 1. Let's say 3 minutes or 00:03:00.
    C1 Would be the duration of the scene, in this case 00:03:00
    A2 would then be 00:03:00 and the start of scene 2
    B2 would be the end of scene 2, let's say 2 minutes 30 seconds
    C2 would then be 00:02:30
    A3 would in turn be 00:05:31 as it's following the elapsed time.

    And so on...

    I've been entering this information manually which is fine but takes a while.

    Recently I discovered a few excel "stopwatches" people have created where you can double click in a cell and excel starts and or stops a stop watch. Very slick. I was hoping to incorporate something similar. Instead of typing time in manually, as I watch the movie when I double click the cell, excel monitors the elapsed time and fills in the respective cell accordingly.

    Does that make sense?

    As a final note while Excel is tracking time for me I need to be able to enter information into other cells such as notes and macros.

    If anyone can steer me the right direction or get me started I would really appreciate this.

    I hope the above made sense. Thanks in advance.

    -D

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Can someone help me create a stopwatch?

    Four buttons on a worksheet, Start, Stop, Mark and Clear, linked to 4 macros.
    Sub StartButton()
        Rem set named value StartTime to Now
        ThisWorkbook.Names.Add Name:="StartTime", RefersTo:="=" & CDbl(Now())
        Rem mark that timer is on
        LastCellInA.Interior.Color = vbYellow
    End Sub
    
    Sub StopButton()
        Dim StartTime As Date
        On Error Resume Next
            StartTime = CDate(Evaluate(Names("StartTime").RefersTo))
        On Error GoTo 0
        
        If 0 < StartTime Then
            Rem if timer is running
            With LastCellInA
                .Interior.ColorIndex = xlNone
                Rem write interval
                With .Offset(0, 2)
                    .Value = Now() - StartTime
                    .NumberFormat = "h:mm:ss"
                End With
                
                Rem calculate adjusted start time
                With .Offset(0, 1)
                    .Value = .Offset(0, 1).Value + .Offset(0, -1).Value
                    .NumberFormat = "h:mm:ss"
                End With
                
                Rem prepare next row
                With .Offset(1, 0)
                    .Value = .Offset(-1, 1).Value
                    .NumberFormat = "h:mm:ss"
                End With
            End With
            
            Rem turn off timer by setting name StartTime to 0
            ThisWorkbook.Names.Add Name:="StartTime", RefersTo:="=0"
        End If
    End Sub
    
    Sub MarkButton()
        If ThisWorkbook.Names("StartTime").RefersTo <> "=0" Then
            Call StopButton
            Call StartButton
        End If
    End Sub
    
    Sub ClearButton()
        Dim strPrompt As String
        If ThisWorkbook.Names("StartTime").RefersTo <> "=0" Then
            strPrompt = "The timer is running" & vbCr & vbCr
        End If
        strPrompt = strPrompt & "Clear data?" & vbCr & "There is no un-do."
        
        If MsgBox(strPrompt, vbYesNo) = vbYes Then
            Call StopButton
            With LastCellInA
                .Resize(1, 3).EntireColumn.ClearContents
                .EntireColumn.Cells(1, 1).Value = 0
            End With
        End If
    End Sub
    
    Function LastCellInA()
        With ThisWorkbook.Sheets("Sheet1")
            Set LastCellInA = .Cells(.Rows.Count, 1).End(xlUp)
        End With
    End Function
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Can someone help me create a stopwatch?

    http://www.excelforum.com/excel-prog...tch-timer.html

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Can someone help me create a stopwatch?

    I can't see that Mike's code doesn't do exactly as requested but here is another post on the forum where the code could be adapted (see sheet in post #1).

    http://www.excelforum.com/excel-prog...bike-laps.html
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Registered User
    Join Date
    06-11-2012
    Location
    Shreveport, Louisiana
    MS-Off Ver
    Excel 2011
    Posts
    7

    Re: Can someone help me create a stopwatch?

    Thanks.

    I'm going to try out all your suggestions today. I'll post back after.

    -D

  6. #6
    Registered User
    Join Date
    06-11-2012
    Location
    Shreveport, Louisiana
    MS-Off Ver
    Excel 2011
    Posts
    7

    Re: Can someone help me create a stopwatch?

    Hi mikerickson

    You code is working really well. The only thing I'd like to alter is the cells in which the times get listed A1-C1 and A2-C2 and so on.

    Instead of the the stop watch moving through the range of A-C. I'd like the stop watch to start in B23 and then list through B23, C23, D23 and then B24, C24, D24 and so on.

    I tried playing around with the offsets and LastCellInA... but I didn't achieve anything other than moving around the interior color. Am going to keep playing with it.

    Any suggestions?

    Thank you.

  7. #7
    Registered User
    Join Date
    04-14-2015
    Location
    India
    MS-Off Ver
    2013
    Posts
    127

    Re: Can someone help me create a stopwatch?

    I need a code to create excel stopwatch & found this amazing link.

    Thanks to all the experts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1