• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Countdown timer backcolor on userform

Villalobos

Active Member
Hello,

I would have a question regarding dynamic textbox backcolor. My target is that if the remaining time is less than 5 seconds then the textbox backcolor is flickering (in every second turning to red and after back to white).

Do you have any idea how to do this?

I have attached a sample file.
 

Attachments

  • Countdown timer.xlsm
    19.1 KB · Views: 91
Hi ,

There are various points which need to be considered when implementing a timer in VBA.

Please go through these links for simple ideas :

1. http://www.daniweb.com/software-development/visual-basic-4-5-6/code/459722/a-timer-for-vba-excel

2. http://sebthom.de/28-excel-vba-timer/

3. http://en.kioskea.net/faq/1115-vba-a-simple-second-timer

Go through these links for more complex ideas :

1. http://www.cpearson.com/excel/OnTime.aspx

2. http://www.tushar-mehta.com/excel/software/vba_timer/

Narayan
 
Hi ,

If you go into the Visual Basic environment by either clicking on the Visual Basic button in the Ribbon or by pressing the key combination ALT F11 , you can see an item named Modules in the Project Explorer pane on the left.

Clicking on Modules will expand it to show the list of all modules in the project ; in the present case there is only one module named Module1 , and it contains the following :

Public Const AllowedTime As Double = 1

The highlighted value is in minutes , and because it is 1 at present , the timer counts for approximately 1 minute.

If you change to it any other value , say 7 , by changing the above to :

Public Const AllowedTime As Double = 7

the timer will count for approximately 7 minutes.

Narayan
 
Thank you Narayan. It worked.

Is there anyway that we can modify the number of minutes thru cell value?

Public Const AllowedTime As Double = worksheets("Sheet1").Range("A1").Value?

I tried this but didn't work.
 
Hi ,

A constant can only be assigned a literal value , which means that the value is specified within the statement itself.

Only a variable can be assigned a value , from another variable , or from a worksheet cell.

You need to change the declaration of AllowedTime slightly ; see the attached file.

Narayan
 

Attachments

  • Countdown timer.xlsm
    20.9 KB · Views: 31
Got it, thanks a lot Narayan. What if I would like to display the countdown timer in TextBox1 in Worksheet not in the Userform? I tried the old VBA code and modify some codes. I inserted active x control textbox and it worked. Unfortunately, when I used the new code you have shared, it appears that I the code is not applicable. MsgBox always popsup. Hope you can help on this.
 
Back
Top