+ Reply to Thread
Results 1 to 7 of 7

Timer in Excel

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Timer in Excel

    Hello,

    I'm trying to create a timer in excel that starts when a cell in range A2:A8 = "Start Timer".

    I've managed to get it to work using this code here, although, I'd like it to only work in the range A2:A8.

    Also, is it possible to have the time difference update automatically every minute.

    Please Login or Register  to view this content.
    Attached, is a copy of the spreadsheet I'm working on.

    Any help would be appreciated.

    Timer.xlsm

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Timer in Excel

    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Timer in Excel

    XeRo Solus has addressed your question about what cells to consider, but your other question regarding the timer is unclear. I am not sure what you have managed to get working because your file has no code to implement a timer so it looks like we're starting from scratch here. Also, your data shows End Times that are earlier than the Start Times, so that adds to the confusion.

    So you want to start a timer when the string "Start Timer" appears in A2:A8. What stops the timer?

    Do you need a separate timer for each row?

    Do you want to blank out the End Time when a timer starts for that row, until the timer stops?

    "Also, is it possible to have the time difference update automatically every minute." If the timer is running, what is the definition of the time difference? That is, if the timer hasn't stopped yet, there is no End Time and therefore "time difference" is meaningless.

    By the way, typing a string into a cell can introduce human error. If it's important to synchronize your Excel timer with some real-world event, a typo will screw it up. You may want to consider a simpler way to start the timer, such as typing any character in column A.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Timer in Excel

    Quote Originally Posted by 6StringJazzer View Post
    XeRo Solus has addressed your question about what cells to consider, but your other question regarding the timer is unclear. I am not sure what you have managed to get working because your file has no code to implement a timer so it looks like we're starting from scratch here. Also, your data shows End Times that are earlier than the Start Times, so that adds to the confusion.

    So you want to start a timer when the string "Start Timer" appears in A2:A8. What stops the timer?

    Do you need a separate timer for each row?

    Do you want to blank out the End Time when a timer starts for that row, until the timer stops?

    "Also, is it possible to have the time difference update automatically every minute." If the timer is running, what is the definition of the time difference? That is, if the timer hasn't stopped yet, there is no End Time and therefore "time difference" is meaningless.

    By the way, typing a string into a cell can introduce human error. If it's important to synchronize your Excel timer with some real-world event, a typo will screw it up. You may want to consider a simpler way to start the timer, such as typing any character in column A.
    1. So to answer your questions. I would like to start the timer when the string "Start Timer" appears in A2:A8. Whenever the range A2:A8 is not equal to "Start Timer", I want to stop the timer.

    2. Yes I need a separate timer for each row. I will possibly have up to 100 of these rows, so I'm not too sure how much CPU it's going to utilize.

    3. Right now, I've made the End Time = NOW(). The difference in time is the timer. The issue though with this, is that it doesn't update. It doesn't matter if the End Time is blanked out, as I can just hide this column.

    4. I'm happy to have the timer tick every minute, as opposed to every second.

    With regards to the string, I plan on having a data validation that starts the timer.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Timer in Excel

    OK, now I have a better idea of what you are doing. I hadn't taken the time to look at your formulas, just focused on the timer aspect.

    You don't need 100 timers running. You need one timer that forces a recalculate once every minute. The code that manages the timer is in a new module called RunTimer. The first time the user select Start Timer in any row, the timer starts running. It does not stop until you exit Excel. If you need to modify your code to force the timer to stop, I have also provided a CancelTimer sub.

    The strategy is that the start time is updated when the user selects Start Timer, and the End Time remains a formula. When the user selects End Timer, the formula is converted to a value. If the user selects Start Timer again for the same row, the End Time is converted back to the formula. In the meantime the timer is recalculating the sheet once per minute to update the End Time formulas.

    Also, your original question was that you only wanted to look at A2:A8 but you said there could be 100 rows. If you add more rows after A8 remember to update the code.
    Attached Files Attached Files

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Timer in Excel

    I should probably add that in VBA, you can set an event to occur in the future. When you request the event, tou provide the name of a Sub to call when you want that event to happen. In this case, the Sub calls itself to simply repeat the event once every minute forever, until Excel is closed.

  7. #7
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Timer in Excel

    Quote Originally Posted by 6StringJazzer View Post
    I should probably add that in VBA, you can set an event to occur in the future. When you request the event, tou provide the name of a Sub to call when you want that event to happen. In this case, the Sub calls itself to simply repeat the event once every minute forever, until Excel is closed.
    Wow thank you so much. That's exactly what I was after. Works perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 12-12-2012, 08:46 PM
  2. Timer in Excel
    By James_SF in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-01-2007, 11:57 AM
  3. Timer in Excel
    By James_SF in forum Excel General
    Replies: 1
    Last Post: 12-29-2006, 11:02 AM
  4. [SOLVED] Stopping a Timer / Running a timer simultaneously on Excel
    By Paul23 in forum Excel General
    Replies: 1
    Last Post: 03-10-2006, 08:10 AM
  5. timer in Excel VBA
    By pham xuan tien in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2005, 06:05 AM

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