Let's say cell A1 has the value 1. I want this cell to increment itself every second.开发者_Python百科 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?
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).
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.
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
精彩评论