문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top