Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

How to make a day timer

0

Greetings 

In my excel sheet i would like to make a count down that includes the formate of days and hours with a set date such as 12:12:00:00 from now or to set it in the format of 11/15/2021 12:00:00

Thanks

Answer
Discuss

Discussion

Hi Tech Mgr and welcome to the Forum

If you're referring to Don's VBA tutorial Countdown Timer in Excel, please say so in your question. Note that tutorial has a cell which is a time value (so making if have a date/time format won't work.

Regarding the mm/d/yyy date part, do you intend that to be today's date say? If so why? (I can't see how having today's date with a count down timer would be useful but perhaps that's just my lack of imagination). Or do you really want to countdown days, months and years?

Please edit your question advise on the above and to add your Excel file via the Add Files... button (without it, it's very hard to give an answer).
John_Ru (rep: 6142) Nov 3, '21 at 5:11 am
Actually am using  your teachexcel sheet the one that have a count down for 5 minutes and i wanted to know how to make it count down from the date time formate for example 11/15/2021 12:00:00pm
tech mgr (rep: 2) Nov 3, '21 at 7:37 am
So you want a countdown for several days, hours, etc.. I'd do that with a target date time and the timer showing the d hh:mm:ss remaining (but doubt I'll have time for that today)- does that sound right?

Please EDIT your question so it contains the data  (and the Title) to say it's a day timer- it's important for other users  and contributors.
John_Ru (rep: 6142) Nov 3, '21 at 8:31 am
yeah i can wait for tomorrow for you to help me with it plz
tech mgr (rep: 2) Nov 3, '21 at 9:03 am
Thanks for changing your question. I'll try to provide a solution tomorrow -(or others might) but please bear in mind we are unpaid volunteers so can't be bound to timescales. 
John_Ru (rep: 6142) Nov 3, '21 at 10:24 am
I understand that and i appreciate your help, looking forward to your answer whenever you can
tech mgr (rep: 2) Nov 4, '21 at 2:32 am
Thank you so much for your effort and time, this is exactly how i wanted it to be
tech mgr (rep: 2) Nov 7, '21 at 4:50 am
Add to Discussion

Answers

0
Selected Answer

Tech Mgr

I've modified (/added to) Don's tutorial file to create a version which will accept a number of days too (they're entered in cell B4, with hh:mm:ss in C4). 

It's not foolproof (and comes with no guarantees) but once you set a time and press Start Timer, it should display the end time (in B2 and C2) and start a second-by-second countdown in green digits. Don't change the font colour though since that used to determine how the digits flash once the timer has finished (alternating yellow and red). The modified code is below (with comments), including a new macro Start_Timer which runs when the Start Timer button is clicked (before the timer macro runs):

Public interval As Date
Sub Start_Timer()
Dim TimeEnd As Date

TimeEnd = Now + Range("B4").Value + Range("C4").Value ' work out end time
Range("B2") = Int(TimeEnd) ' get end date
Range("C2") = TimeEnd - Range("B2") + TimeValue("00:00:01") ' get end time
Timer 'start timer

End Sub
Sub Timer()
' TeachExcel.com

    ' Check if the timer is finished and skip countdown if it is
    If Range("B4").Value + Range("C4").Value = 0 Then
        With Range("B4:C4")
            If .Font.Color <> vbRed Then
                .Font.Color = vbRed
                Else
                .Font.Color = vbYellow
            End If
        End With
        GoTo OneSec
    End If


    ' Check if a day has elasped
    If Range("B4").Value > 0 And Range("C4") = 0 Then Range("B4").Value = Range("B4").Value - 1

    If Range("C4") = 0 Then
        Range("C4").Value = TimeValue("23:59:59")
        Else
        ' Remove 1 second from the timer
        Range("C4").Value = Range("C4").Value - TimeValue("00:00:01")
    End If
OneSec:
    ' Set when the macro should run again - should be the same time value
    ' as the previous line.
    interval = Now + TimeValue("00:00:01")

    ' Make this macro run again in 1 second
    Application.OnTime interval, "timer"

End Sub
Sub stop_timer()
' TeachExcel.com
    On Error Resume Next 'in case timer isn't running
    ' Stop the timer macro from running
    Application.OnTime EarliestTime:=interval, Procedure:="Timer", Schedule:=False

End Sub
Sub reset_timer()
' TeachExcel.com

    ' Default time for the timer
    Range("B4").Value = 0
    Range("C4").Value = "00:01:00"
    Range("B4:C4").Font.Color = vbGreen
    Range("B2:C2") = ""
End Sub
I've also added some workbook event macros so (hopefully) you can set a timer running for more than a day and quit or turn off your computer in the meantime (provided you save it). When it's re-opened, it should continue the countdown. The code for those covers what happens when you open and close the workbook and is as follows:
Private Sub Workbook_Open()
Dim TimeLeft As Date

' Check if timer was set
If Range("B2") = "" And Range("C2") = "" Then Exit Sub

'Has target been reached?
If (Range("B2") + Range("C2")) <= Now Then
    'if so, zero timer and start (to flashing)
    Range("B4") = 0
    Range("C4") = TimeValue("00:00:00")
    Timer
    Exit Sub
    'if time to go, set days and time remaining
    Else
    TimeLeft = (Range("B2").Value + Range("C2").Value) - Now ' work out time left
    Range("B4") = Int(TimeLeft) ' set days left
    Range("C4") = TimeLeft - Range("B4") 'set hh:mm:ss left
End If

Timer 'start timer

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case timer isn't running
stop_timer

End Sub
The worksheet is proteced (as it leaves me) but if you could unprotect it (there's no password) if you want to stop the timer and change values in B2 and C2 e.g. to check what happens at day ends, for future days. 

Again, no guarantees on this. Also I haven't allowed you to set a target date/time but perhaps you can do that.

Suggest that you don't mess with the time interval 00:00:01 (a second).

Hope this helps.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login