Question

I would like to know if it's possible to add value using time?

For example, I want to add 100 to a cell every minute that has that has passed which would cause the value of the cell to increase by 6,000 by the end of the hour.

Was it helpful?

Solution

Run StartTimer to start the incrementation and StopTimer to stop the incrementation. The cell in question is B9 :

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
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()
    Range("B9").Value = Range("B9").Value + 100
    Call StartTimer
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top