+ Reply to Thread
Results 1 to 20 of 20

Best way to make multiple countdown timers

Hybrid View

  1. #1
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Best way to make multiple countdown timers

    Hi Dave_ross
    Try this code in you workbook

    Option Explicit
    Dim iTimer As Date
    Dim zTimer As Date
    Dim xCount As Date
    Dim iCount As Date
    Dim eTime As Date
      Dim XCell As Range
    Dim iBoolean As Boolean
    Dim iiBoolean As Boolean
    Dim iiiBoolean As Boolean
    Sub start_timers()
        With ThisWorkbook.Sheets(1)
            .Range("C3") = TimeValue("00:00:10")
            .Range("E3") = TimeValue("00:00:10")
            .Range("G3") = TimeValue("00:01:50")
            .Range("G10") = ""
            .Range("C10") = "Started"
        End With
      iBoolean = True
    iiBoolean = True
    iiiBoolean = True
        MasterTimer
    End Sub
    Sub MasterTimer()
      
        
        If iBoolean Then
            xCount = TimeValue("00:00:10")
            Set XCell = ThisWorkbook.Sheets(1).Range("C3")
            eTime = TimeValue("00:00:10")
            iCount = TimeValue("00:00:01")
            iBoolean = False
            UpdateiTimer
            STimer
        ElseIf iiBoolean Then
            xCount = TimeValue("00:00:10")
            iCount = TimeValue("00:00:01")
            Set XCell = ThisWorkbook.Sheets(1).Range("E3")
            eTime = TimeValue("00:00:10")
             iiBoolean = False
            UpdateiTimer
            STimer
        ElseIf iiiBoolean Then
            xCount = TimeValue("00:01:50")
            iCount = TimeValue("00:00:01")
            Set XCell = ThisWorkbook.Sheets(1).Range("G3")
            eTime = TimeValue("00:01:50")
             iiiBoolean = False
            UpdateiTimer
            STimer
        Else
            KillTimers
        End If
    End Sub
    Sub UpdateiTimer()
        XCell = xCount
        iTimer = Now + TimeValue("00:00:01")
        xCount = xCount - iCount
        Application.OnTime iTimer, "UpdateiTimer"
    End Sub
    Sub STimer()
        zTimer = Now + eTime
        Application.OnTime zTimer, "StopTimers"
    End Sub
    Sub StopTimers()
        On Error Resume Next
        Application.OnTime iTimer, "UpdateiTimer", , False
        Application.OnTime zTimer, "STimer", , False
        MasterTimer
    End Sub
    Sub KillTimers()
        On Error Resume Next
        Set XCell = Nothing
         Application.OnTime iTimer, "UpdateiTimer", , False
        Application.OnTime zTimer, "STimer", , False
        ThisWorkbook.Sheets(1).Range("G10") = "Stopped"
        ThisWorkbook.Sheets(1).Range("C10") = ""
    End Sub
    but dont forget to put
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
     Call KillTimers
    End Sub
    in "Thisworkbook" Module
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  2. #2
    Registered User
    Join Date
    11-25-2011
    Location
    Inverness
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Best way to make multiple countdown timers

    Perfect thanks

  3. #3
    Registered User
    Join Date
    11-25-2011
    Location
    Inverness
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Best way to make multiple countdown timers

    Thats great works a dream.

    really gonna pick your brains now though...

    What if i wanted to have these count down timers running but also have others running in other rows? do i create a new module with the correct cell numbers? I tried this and its telling me i have ambiguous names?

    i want each row of counters to work independently if i can?

    ill attach a copy to show you
    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)

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