+ Reply to Thread
Results 1 to 4 of 4

How to: Button to subtract :05 from a simulated "Game" Clock...

  1. #1
    Registered User
    Join Date
    03-25-2020
    Location
    Michigan
    MS-Off Ver
    Home 365
    Posts
    12

    How to: Button to subtract :05 from a simulated "Game" Clock...

    Hello. New to the forums here and also fairly new to these Excel features. Looking for some guidance for something I haven't been able to figure out.

    I'm trying to set up a Game clock for a simulated sports game. I would like to set up a cell to show the game clock, starting at 20:00 (minutes) of time and set up a macro that will reduce that time by :05 (seconds) each time the button is clicked. Then, when it reaches 0:00, to start back to 20:00 with the next button click.

    I have been successful in getting the Game clock cell to show the 20:00 in the correct time format. I have also successfully recorded a macro (and assigned a button) that reduced the game clock cell by :05 with a button click.

    My issue is that the macro/button only reduced the game clock once (to 19:55). Every subsquent button click does nothing further. The game clock just continues to display 19:55.

    So, what I'm missing is how to get the button click to reduce the game clock cell by an additional :05 every time it's selected, until it reaches 0:00 and then resets to 20:00 with the next click. Is this called a loop?

    I hope this makes sense. Any direction would be appreciated.
    Attached Files Attached Files
    Last edited by mark2323; 03-25-2020 at 12:07 PM. Reason: Adding Sample

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: How to: Button to subtract :05 from a simulated "Game" Clock...

    Administrative note

    Welcome to the forum

    in your haste to solve your problem, you probably missed the yellow banner advising how to get answers faster by posting a sheet ?

    Please take a moment to read it and attach a sheet accordingly.

    Thanks you for helping us help you

  3. #3
    Registered User
    Join Date
    03-25-2020
    Location
    Michigan
    MS-Off Ver
    Home 365
    Posts
    12

    Re: How to: Button to subtract :05 from a simulated "Game" Clock...

    Sorry I missed the attachment. Original post is now editted with attachment.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to: Button to subtract :05 from a simulated "Game" Clock...

    Hi mark and welcome to ExcelForum,

    See the attached file for a modified copy of your file which contains the code below.

    In your original code below, you were thinking in terms of a spreadsheet formula. All this does is subtract 5 seconds from 20 minutes each and every time you Click.
    Please Login or Register  to view this content.
    The following is a first attempt to do what you want. It gets the value from the Cell. It subtracts 5 seconds similar to your formula. It puts the value back in the spreadsheet.
    It can be done in one line but it isharder to read and much harder to debug that way.
    Unfortunately, this fails and generates a RUNTIME ERROR when going from 5 seconds to ZERO.
    Please Login or Register  to view this content.
    Here is the second attempt which 'traps' the error generated above. The items in red are the changes.
    Please Login or Register  to view this content.
    Here is a third method that displays the value as text instead of as a Date:
    Please Login or Register  to view this content.
    To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. Dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    To manually set a breakpoint, see http://www.wiseowl.co.uk/blog/s196/breakpoints.htm

    --------------

    Enjoy.

    Lewis

+ 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. [SOLVED] Excel 2007: How to Convert "5/2/2013" to "May" then subtract a Month so it's "Apr"
    By Golom in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-19-2013, 02:00 AM
  2. Replies: 1
    Last Post: 10-23-2013, 05:20 PM
  3. Create a Command Button to "Save As" and "Close" an Excel Workbook
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2013, 05:38 PM
  4. Replies: 1
    Last Post: 01-27-2012, 11:25 PM
  5. Rearrange format with "TRIM" and "SUBTRACT" functions
    By Vittorio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2011, 07:37 PM
  6. Making the Tools>Options...Calculation "Manua"l Vs "Automatic" a Button.
    By Ecoich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 07:50 PM
  7. [SOLVED] Replace "insert function" with "edit formula" button in fourmula b
    By 13brian in forum Excel General
    Replies: 0
    Last Post: 08-24-2005, 04:05 PM

Tags for this Thread

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