Of course you can also add logic to recalculate the sheet automatically at regular intervals. One way to do this could be to add a new module with, for example, the following code:
Private Running As Boolean
Public Sub StartTimer()
Running = True
Call TimerEvent
End Sub
Public Sub StopTimer()
Running = False
End Sub
Public Sub TimerEvent()
Workbooks("Book1").Worksheets(1).Calculate
If Running Then
Application.OnTime Now + TimeValue("00:00:10"), "TimerEvent"
End If
End Sub
(Note that you'd need to replace "Book1" with the appropriate name, or simply use ActiveWorkbook
in place of Workbooks("Book1")
, although then the timer will be recalculating whatever workbook you have open at the moment).
You can start the timer by running the StartTimer
macro (using the "Run" button) and stop it using StopTimer
.
It might make sense to also add something like this to the code of ThisWorkbook
module, so that the timer will start and stop automatically:
Private Sub Workbook_Open()
Call StartTimer
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub