Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Excel - How to refresh a cell automatically every 5 seconds?

Tags:

refresh

excel

vba

I have a cell in my Excel sheet and I need this cell to be refreshed every 5 seconds.

MS Excel itself enables to set refreshing but it is only every 1 minute and that is insufficiently too long..

I need some code in VBA or macro set to be run every 5 seconds and do exactly what would be done if I clicked Refresh every 5 seconds as it is shown here:

Refresh

Somehow I didn't find any example of that I have absolutely no clue how to do that as I don't know how to work in VBA..

like image 448
Totallama Avatar asked Nov 15 '25 21:11

Totallama


2 Answers

You can use Application.OnTime to schedule the auto refresh. Do create the below VBA subroutine and execute. It will auto calculate cell A1 every 5 seconds.

Sub UpdateCell()
    ActiveWorkbook.RefreshAll
    Application.OnTime Now + TimeValue("00:00:5"), "UpdateCell"
End Sub
like image 75
AlbertLau14100 Avatar answered Nov 18 '25 21:11

AlbertLau14100


Got it, now it works:

Sub UpdateCell()
    ActiveWorkbook.RefreshAll
    Application.OnTime Now + TimeValue("00:00:5"), "List1.UpdateCell"
End Sub
like image 36
Totallama Avatar answered Nov 18 '25 20:11

Totallama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!