avatarmonkeykirby
avatarmonkeykirby

Reputation: 339

Automatically increment an excel cell value periodically

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?

Upvotes: 1

Views: 7752

Answers (3)

Mike C
Mike C

Reputation: 1

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

Upvotes: 0

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.

Upvotes: 1

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).

Upvotes: 2

Related Questions