I want vba code which change back color of b2 between “yellow color,green,orange” every 5 seconds
I want vba code which change back color of b2 between “yellow color,green,orange” every 5 seconds
See Help for the Application.OnTime method.
Entia non sunt multiplicanda sine necessitate
I can't understand where the solution .sorry
Paste this code into the sheet level module :
![]()
Option Explicit Sub chngColor() Sheets("Sheet1").Range("B2").Interior.Color = RGB(255, 255, 0) Application.Wait (Now + TimeValue("00:00:05")) Sheets("Sheet1").Range("B2").Interior.Color = RGB(0, 255, 0) Application.Wait (Now + TimeValue("00:00:05")) Sheets("Sheet1").Range("B2").Interior.Color = RGB(255, 153, 0) Application.Wait (Now + TimeValue("00:00:05")) callMeAgn End Sub Sub callMeAgn() Call chngColor End Sub
Hello sterio,
Maybe you would like to try this alternative;
Regards.![]()
Option Explicit Public RunWhen As Double Public Const cRunIntervalSeconds = 5 Public Const RunIt = "ColorChange" Dim iCount As Integer Sub StartTimer() RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds) Application.OnTime EarliestTime:=RunWhen, Procedure:=RunIt, _ Schedule:=True End Sub Sub ColorChange() Dim cTime As Date Sheet1.Shapes("Button 3").Visible = msoFalse Sheet1.Shapes("Button 5").Visible = msoFalse cTime = Now Application.OnTime cTime + TimeValue("00:00:05"), "ColorChange" iCount = iCount + 1 Sheet1.Range("B2").Interior.ColorIndex = Choose(iCount, 6, 4, 45) If iCount = 3 Then iCount = 0 Application.OnTime cTime + TimeValue("00:00:05"), "ColorChange", , False StartTimer If Sheet1.Range("B2").Interior.ColorIndex = 45 Then Sheet1.Shapes("Button 3").Visible = msoTrue Sheet1.Shapes("Button 5").Visible = msoTrue Sheet1.Range("B2").Interior.ColorIndex = 45 End If End If End Sub Sub StopTimer() On Error Resume Next Application.OnTime EarliestTime:=RunWhen, Procedure:=RunIt, _ Schedule:=False End Sub Sub ClearB() Sheet1.Range("B2").Interior.ColorIndex = xlColorIndexNone Sheet1.Shapes("Button 3").Visible = msoFalse Sheet1.Shapes("Button 5").Visible = msoFalse End Sub
Please consider:
Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
1000000000000 thanks to winon& 1000 thanks to logit :D AS WINON CODE IS better
1000000000000 thanks to winon& 1000 thanks to logit :D AS WINON CODE IS better
Oh ... oh .... I'm hurt.Perhaps, even bleeding a little.
My totals :
Posts 1,043
Winon's totals :
Posts 4,478
Me thinks there is something amiss ! Ne'er ... this shall not go unanswered Sir !
A duel ! I demand my just recompense. Tomorrow at high noon on the front lawn.
Your choice of pistols ....
(and to think all of this was due to an extra two silly buttons)
@ Logit,
You have to learn how to lose before you can win!LOL
I accept your request for just recompense, as I am humiliated and hurt by your arrogant and insensitive comment, quote, "(and to think all of this was due to an extra two silly buttons)", end quote.
Forget the pistols since I am a renowned marksman, which will be a too easy way for you to pass on from your miserable life thus far. I choose you to suffer the most horrendous painful demise by my deadly hands, faster than lightning inflicting the worse pain you could ever imagine, until you will rather choose to depart out of free will.
Your choice!![]()
Thank you for the Rep sterio.
Cheers guys!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks