Automatically Update Time and Date

Tatsumaru

New Member
Joined
Mar 5, 2004
Messages
3
How can I make cells I10 and I11, with =TODAY() and =NOW() in them, respectively. I have set up =NOW() to only show the time. I need this time to be updated every minute, is there a way for excel to automatically do that. Perhaps with auto_open macro.

Thanks in advance
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You can use Application.OnTime to execute a macro after a scheduled delay. So you might want to use something like this in your Workbook code:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.OnTime NextScheduledUpdate, "UpdateDateTime", , False
End Sub

Private Sub Workbook_Open()
    UpdateDateTime
End Sub
Then in a separate module:
Code:
Public NextScheduledUpdate As Variant

Sub UpdateDateTime()
    Range("MyDate").Calculate
    Range("MyTime").Calculate
    
    NextScheduledUpdate = Now + TimeSerial(0, 1, 0)
    Application.OnTime NextScheduledUpdate, "UpdateDateTime"
End Sub
 
Upvote 0
Hi Tatsumaru,

For an accurate time update you can try the following codes:

Place this code in the ThisWorkBook Module:


<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
    <SPAN style="color:#00007F">Dim</SPAN> CalcTime <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    CalcTime = Format(WorksheetFunction. _
    Ceiling(Timer, 60) / 86400, "long time")
    Application.OnTime TimeValue(CalcTime), "UpdateTime"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


And this code in a Standard Module :


<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UpdateTime()
    Range("I11").Calculate
    Application.OnTime Time + _
    TimeSerial(0, 1, 0), "UpdateTime"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


Save,close and reopen the workbook and you are done.

Regards.
 
Upvote 0
thank you both of you. I have, with the help of my friend (and you two!), now sorted the updating time problem.

Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top