Ashley Wellington
Ashley Wellington

Reputation: 3

Add to value with time (Excel)

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.

Upvotes: 0

Views: 41

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

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

Upvotes: 1

Related Questions