• 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.

Changing color of a cell every second autmatically

This code is based on Chip Pearson's example:
Code:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "refresh"

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
        schedule:=True
End Sub

Sub StopTimer()
  On Error Resume Next
  Application.OnTime earliesttime:=RunWhen, _
      procedure:=cRunWhat, schedule:=False
End Sub

Sub refresh()
    With Application.WorksheetFunction
        Range("B2").Interior.ColorIndex = .RandBetween(1, 56)
    End With
    Call StartTimer
End Sub

Run StartTimer to begin and StopTimer to end.
 
You will need to use some VBA code to update a cell every second with say True/False
Then use that cell to control the CF

I'd strongly recommend against it as you are going to place a load on your PC and the change may trigger all Volatile Functions to recalculate
 
This code is based on Chip Pearson's example:
Code:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 1
Public Const cRunWhat = "refresh"

Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
        schedule:=True
End Sub

Sub StopTimer()
  On Error Resume Next
  Application.OnTime earliesttime:=RunWhen, _
      procedure:=cRunWhat, schedule:=False
End Sub

Sub refresh()
    With Application.WorksheetFunction
        Range("B2").Interior.ColorIndex = .RandBetween(1, 56)
    End With
    Call StartTimer
End Sub

Run StartTimer to begin and StopTimer to end.
Hello Gary's Student,
Thank you so much. I checked the code and it is working exactly the way I expected. Can you also please advice me how can I accomplish running a macro automatically when I start an excel workbook?
 
Back
Top