I have graphs that are updated based on the value in one cell. I am trying to write a script that changes the value in this cell every second and updates the graphs in the process.
The program does not wait one second to call the procedure and rather runs everything directly.
I tried other methods such as Application.wait which works in regards to waiting but it does not update the graphs.
Why doesn't Application.OnTime wait one second?
Sub graphOverTime()
Do While Range("N5").Value = "Running"
'changes cell N5 to Not running on condition
Call my_procedure
'Update value in D3 that impacts the graphs
current_month = Range("D3").Value
Range("D3").Value = Application.WorksheetFunction.EoMonth(current_month, 1)
DoEvents
'Wait one second to rerun procedure
Application.OnTime Now + TimeValue("0:00:01"), "graphOverTime"
Loop
End Sub
Your main problem is
Do Whilelooping which causesApplication.OnTimeto set overlapping scheduled calls ofgraphOverTime. Following is one way of doing what you wanted to in the first place