TIMER COUNTDOWN

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

I am trying to make a countdown timer. In a userform.The userform is called UI

The problem i am having, is this

if MY_TIME as in the past, the timer counts up, showing the elapsed time. This is correct.
HOWEVER
if MY_TIME is in the future, i get a huge number, like nearly 24 hours, counting up.

its like i cant get negative time.

Any help would be appriciated


VBA Code:
Sub UPDATE_CLOCK()
Dim MY_TIME As Date
Dim DIFF As Date
UI.CLOCK = Format(Now, "HH:MM:SS")
If UI.CB1 <> "" Then
    MY_TIME = Left(UI.CB1, 5)
    DIFF = Format(MY_TIME - Now, "HH:MM:SS")
    UI.COUNT_DOWN = DIFF
End If
Application.OnTime Now + TimeSerial(0, 0, 1), "UPDATE_CLOCK"
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
change DIFF = Format(MY_TIME - Now, "HH:MM:SS") to DIFF = Format(MY_TIME - Time, "HH:MM:SS")

The reason you have a problem is because Now returns a date element. Time only returns a time.

Seems to work for me.

HTH
 
Upvote 0
Solution
the timer counts up, showing the elapsed time. This is correct.

I am trying to make a countdown timer
These goals are mutually exclusive? How can the same timer increment (count up) showing elapsed time and be correct and still count down (which is typically to zero)? If you're saying you want negative numbers you could try multiplying by -1.
 
Upvote 0
Hi pjmorris,

that worked perfectly thankyou.

Micron, thanks for your help too.

Dave
 
Upvote 0
Delighted to have helped. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top