Home » excel » Automatically increment an excel cell value periodically

Automatically increment an excel cell value periodically

Posted by: admin May 14, 2020 Leave a comment

Questions:

Let’s say cell A1 has the value 1. I want this cell to increment itself every second.
So after 1 second, cell A1 now has the value 2. After two seconds the value is 3, etc, etc, etc.

How can I set that up?

How to&Answers:

Here’s a way to do it using VBA:

Sub CellTimer()

    Sheet1.Range("A2").Value = 1
    Do
        Application.Wait (Now() + TimeValue("0:00:01"))
        Sheet1.Range("A2").Value = Sheet1.Range("A2").Value + 1
    Loop

End Sub

This has its quirks, but I don’t know what you’re going to use this for, so I don’t know, maybe this will suit your purposes.

Answer:

You could use this:

=ROUND(NOW()*24*3600,0)-3522649665

where 3522649665 is just an arbitrary offset. You may have to force a recalculation using F9 or the VBA command Sheet1.Range("A1").Calculate (assuming you put the formula in cell A1).

Answer:

This works for me for recalculating every second:

Sub CalculateNow()
    'Your code here
    'i.e.
    Calculate 'This recalculates all your cell values


    Application.OnTime Now + TimeValue("00:00:01"), "CalculateNow"
End Sub