countdown timer

0lzi

New Member
Joined
Sep 13, 2011
Messages
26
2sbrf42.png


here is a picture to help visualise what im trying to do.

im trying to get the system time, then getting time from the user from inputbox, then display the difference in a shapes text box and loop untill the timeleft = 0

code i have so far:
Code:
Sub RoundedRectangle1_Click()

Dim setTimer
Dim currentTime
Dim timeLeft As Single

setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")

currentTime = Time

timeLeft = setTimer - currentTime

With ActiveSheet.Shapes("Rounded Rectangle 1") _
.TextFrame.Characters.Text = ("& timeLeft &")
End With

End Sub

i have not included a loop yet i am just wanting to display the time difference, between the two times.
 
This worked for me:

Code:
Sub RoundedRectangle1_Click()
    Dim setTimer
    Dim currentTime As Date
    Dim timeLeft As Date
    setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")
    Do
        currentTime = Time
        timeLeft = TimeValue(setTimer) - currentTime
        With ActiveSheet.Shapes("Rounded Rectangle 1")
            .TextFrame.Characters.Text = "" & timeLeft & ""
        End With
        Application.Wait Now + TimeValue("00:00:01")
    Loop While timeLeft > TimeValue("00:00:00")
End Sub
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
thanks :D

is there a better way of doing this ? because when i look in taskmanager, EXCEL.EXE is using 25% CPU.

its probably because its running the loop as fast as it can and pausing for a second.

i also still need a break for when i want to close the application, or have a pause button or somthing.

also is there a way of starting that sub when the file opens, and for the window to be a certain size?

sorry for all the questions
 
Last edited:
Upvote 0
An OnTime procedure may be less processor intensive.

You can stop the macro by pressing Esc or Ctrl+Break.

You can call the procedure from the Workbook_Open event procedure.

If you record a macro while sizing the window you will get some VBA code.
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,208
Members
453,151
Latest member
Lizamaison

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