+ Reply to Thread
Results 1 to 10 of 10

Excel Stopwatch Help [VBA]

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    arlington,texas
    MS-Off Ver
    Excel 2003
    Posts
    8

    Excel Stopwatch Help [VBA]

    Hello VBA gurus!

    I'm currently using this code from another forum (http://www.mrexcel.com/forum/excel-q...tml#post171939) to make a stopwatch, but now I want to modify it a little to make it display how long I take to do things and if I pass a certain time period too much.
    It's on a userform with 4 buttons: Start, Stop, Reset, and Exit.
    I was wondering if it's possible to have it where when I press either Stop or Reset that it will store what ever time the stopwatch was at and display it on a label. Then if the stopwatch was above or below a certain time frame then it would display on a different label and have a running total until the user presses the Exit button.

    Example:
    Stopwatch is running. User presses Stop/Reset after 10 seconds have passed.
    10 seconds would be displayed on label 1.
    User starts stopwatch again, and presses Stop/Reset after 1 minute has passed.
    1 minute would be displayed on label 2.
    User starts stopwatch again, and presses Stop/Reset after 59 seconds have passed.
    59 seconds would then be added to the 10 seconds on label 1.
    User starts stopwatch again, and presses Stop/Reset after 1 minute and 59 seconds have passed.
    1 minute and 59 seconds would then be added to the 1 minute on label 2.
    (repeat)


    What I know/tried so far:
    I originally tried setting an "If/Then" procedure in the ResetBtn_click sub and made it read something along the lines of "If elapsedtimelbl.caption = "00:00:01.00" then label1.caption = elapsedtimelbl, but that didn't work, it only ended up showing me elapsedtimelbl instead of the stopped time.
    So I came to the conclusion that I have to set it as a string and store it within memory somehow.

    Note:
    I can't download APIs since I use this only at work.

    Thank you any help provided and thank you for taking the time to read this post,
    lilhugo


    Dim StopTimer As Boolean
    Dim Etime As Single
    Dim Etime0 As Single
    Dim LastEtime As Single
    Dim TimeAbove1Minute as String
    Dim TimeBelow1Minute as String
    
    
    
    Private Sub ExitBtn_Click()
    Unload Me
    End Sub
    
    Private Sub ResetBtn_Click()
    StopTimer = True
    Etime = 0
    Etime0 = 0
    LastEtime = 0
    ElapsedTimeLbl.Caption = "00:00:00.00"
    End Sub
    
    Private Sub StartBtn_Click()
    StopTimer = False
    Etime0 = Timer() - LastEtime
    Do Until StopTimer
    Etime = Int((Timer() - Etime0) * 100) / 100
    If Etime > LastEtime Then
    LastEtime = Etime
    ElapsedTimeLbl.Caption = Format(Etime / 86400, "hh:mm:ss.") & Format(Etime * 100 Mod 100, "00")
    DoEvents
    End If
    Loop
    End Sub
    
    Private Sub StopBtn_Click()
    StopTimer = True
    End Sub

  2. #2
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Excel Stopwatch Help [VBA]

    Is it important that you use a stopwatch? Or can you use an actual time value from the system clock?

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    arlington,texas
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Excel Stopwatch Help [VBA]

    Well, I've used a macro that did a kind of countdown, but it didn't really help me. So I figured a stopwatch would be a little bit more useful.

  4. #4
    Registered User
    Join Date
    08-23-2012
    Location
    arlington,texas
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Excel Stopwatch Help [VBA]

    Crap. I noticed today that the stopwatch is hogging a lot of resources. :/
    I doubt there's anyway to fix that, but does anyone know if it's possible????

  5. #5
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Excel Stopwatch Help [VBA]

    What you could use is a time stamp that works just as well and will of course capture hh:mm:ss. The good part is, it will not be constantly running. If I understood a little more about how you need to use it, I could probably help you come up with something.

  6. #6
    Registered User
    Join Date
    08-23-2012
    Location
    arlington,texas
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Excel Stopwatch Help [VBA]

    Oh cool. What is a time stamp actually?

    I'm wanting to make a stopwatch that can help me know much time i spend working data entry orders.
    I need it to separate how much time i spend on orders above 3 minutes and below 3 minutes and display both in 2 separate labels. Whenever I press stop or reset I need it to add to either the above or below 3 minutes label depending on time.

  7. #7
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Excel Stopwatch Help [VBA]

    A time stamp is just capturing the time from your system clock. Look at this attached file, this is what I use to keep track of down-time on a machine. It logs the total time on Sheet1. You could modify this to your liking.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-23-2012
    Location
    arlington,texas
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Excel Stopwatch Help [VBA]

    Awesome, I like it! It's working out pretty well.
    Is there a way to separate the time into a different column when it passes a certain point on the excel spreadsheet?

    i.e.
    Under 5:00 minutes would show on column C.
    Above 5:01 minutes would show on column D.
    Last edited by lilhugo; 04-04-2013 at 11:44 AM.

  9. #9
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Excel Stopwatch Help [VBA]

    Yes, I think there would have to be an IF statement in column C along with the formula there now, hopefully someone else can assist with doing that.

  10. #10
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Excel Stopwatch Help [VBA]

    See if THIS can be of some help to you with time stamping when a cell is clicked.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

+ 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