+ Reply to Thread
Results 1 to 2 of 2

Adding a Pause Button into a time on excel

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    1

    Adding a Pause Button into a time on excel

    Hi,

    I'm trying to create a lap time in Excel which also features a Pause button. So far, I have managed to create Start and Lap buttons, with the following code:

    Sub StartButton_Click()
        Range("A:B").ClearContents
        Range("A1") = "Start"
        startTime = Timer
    End Sub
    ---
    Sub LapButton_Click()
        Dim finalTime As Single, lr As Long
        finalTime = Timer - startTime
        lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
        Cells(lr, "A") = Format(finalTime, "0.000")
        If lr = 2 Then Cells(lr, "B") = Cells(lr, "A")
        If lr > 2 Then Cells(lr, "B") = Cells(lr, "A") - Cells(lr - 1, "A")
    End Sub
    ---
    I want to create a Pause button which - unsurprisingly! - will allow me to pause the timer when I press it, and then allow the timer to continue where it left off after pressing it again (or by pressing another button if need be). I want all the data from before the pause to be saved as well, as I'm taking averages of the most recent laps.

    I've tried a couple of different codes but had nothing which works at all at the moment. Any suggestions / advice would be greatly appreciated!

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,427

    Re: Adding a Pause Button into a time on excel

    Option Explicit
    
    Dim CountDown As Date
    Sub Timer()
        CountDown = Now + TimeValue("00:00:01")
        Application.OnTime CountDown, "Reset"
    End Sub
    
    Sub Reset()
    Dim count As Range
        Set count = [A1] ' A1 contains the number of seconds for the countdown.
            count.Value = count.Value - 1
        If count <= 0 Then
            MsgBox "Countdown complete."
            Exit Sub
        End If
            Call Timer
    End Sub
    
    Sub DisableTimer()
        On Error Resume Next
        Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False
    End Sub
    Attached Files Attached Files

+ 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. running timer in excel with start, pause and end button
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-23-2021, 04:36 AM
  2. [SOLVED] pause button in excel
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2015, 10:16 PM
  3. [SOLVED] Is it possible to pause a macro with a button on the worksheet?
    By Mr.GfCs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2015, 07:48 PM
  4. Play Stop and Pause Button
    By Stanley91 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2014, 12:03 PM
  5. Pause and resume button using VBA
    By kyod in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-08-2009, 08:36 AM
  6. Abort button for a macro(not the break key) and pause/resume button
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-21-2009, 04:22 AM
  7. Excel 2007 : Macro pause button
    By Terri_Galloway in forum Excel General
    Replies: 2
    Last Post: 02-11-2009, 12:45 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