+ Reply to Thread
Results 1 to 8 of 8

Stop a macro on a button

  1. #1
    Registered User
    Join Date
    01-19-2013
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    4

    Stop a macro on a button

    I am newbie to this so i maybe asking very stupid questions!

    I have a macro that refreshes a =NOW() every 10 seconds, but it has to keep the workbook on one sheet (driver stint times) , I have two buttons that will take the user to two different sheets, but every 10 seconds it goes back to the original worksheet.

    The code that takes user to the different worksheet is as simple as:

    Sub stats()
    '
    ' stats Macro
    '

    '
    Sheets("Car Stats").Select
    End Sub

    Is there something I can put into this to stop the macro?

    And then some code that I can use to restart the macro when they click the button to return to the sheet with the =NOW() on it?

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Stop a macro on a button

    Just don't use the Select statement. You can refresh that =Now() function in an easier way.
    Please Login or Register  to view this content.
    Last edited by RHCPgergo; 01-29-2013 at 06:01 AM.

  3. #3
    Registered User
    Join Date
    01-19-2013
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Stop a macro on a button

    Will that keep refreshing the =Now() automatically? Im using it to work out the stint times of an endurance car, and the amount of fuel used, so i need it to keep refreshing the current time

  4. #4
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Stop a macro on a button

    It will calculate all functions on the "Car Stats" worksheet each time the macro is run. So yeah, if the =Now() function is on that worksheet, it will be refreshed.

  5. #5
    Registered User
    Join Date
    01-19-2013
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Stop a macro on a button

    Sorry to be a pain, but i have used someone's code for the refreshing, what code would you use to make that code refresh every 10 seconds ? or can you adjust this code? Sorry im very new to this!!


    Public RunWhen As Double
    Public Const cRunIntervalSeconds = 10 ' 10 seconds
    Public Const cRunWhat = "The_Sub" ' the name of the procedure to run


    Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
    End Sub
    Sub The_Sub()
    Sheets("Driver Stint Times").Select
    [B4] = Now
    ' Call StartTimer to schedule the procedure again
    StartTimer

    Sheets("Home").Select
    End Sub

  6. #6
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Stop a macro on a button

    How about a macro that runs each time you enter something in any cell in a workbook? I think that fits your needs better. Try copying this into the thisworkbook module. You don't need to push any button for it to start. It's an event macro and these kind of macros run each time a certain event takes place. This one runs each time a cell's value is changed in a workbook.
    Please Login or Register  to view this content.
    Last edited by RHCPgergo; 01-29-2013 at 07:09 AM. Reason: typo. corrected "stints" to "stint"

  7. #7
    Registered User
    Join Date
    01-19-2013
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Stop a macro on a button

    Thats Brilliant Thank you very much!!!!

  8. #8
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Stop a macro on a button

    Glad to help.
    Please mark the thread solved so next time someone does a search it's easier to find an answer.

+ 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