date and time

AT_2003

New Member
Joined
Dec 16, 2002
Messages
27
hi all

I was woundering if there is a way off putting the date and time on my spreadsheet so it regulary updates.
For example when u open the workbook it should say the time and date but the time should move digitaly and after 24hours the date should automatically change. Is this possible.

thanx
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try using the function = NOW() in two consecutive cells. Then format one of them as hh:mm and the other as date.
I hope it works
 
Upvote 0
You can use the
=NOW() function in a cell and format the way you want it. But it only updates when the sheet is calculated.

HTH
 
Upvote 0
Is there a way i can get them moving digitally for example the seconds moving and the time automatically when i open the spreadsheet the time is moving already.

thanx
 
Upvote 0
Not sure why the system clock isn't sufficient, but this will put an updating clock in a cell:

Code:
Sub clock()

ActiveWorkbook.Worksheets(1).cells(1, 1).Value = _
Format(Now, "hh:mm:ss")
Application.OnTime (Now + TimeSerial(0, 0, 1)), "clock"
End Sub

can't remember where I got it...

paddy
This message was edited by PaddyD on 2003-01-06 19:33
 
Upvote 0
Try the following.
It will, however, cause an irritating flicker of the cursor.

Put in the Workbook module :-

Private Sub Workbook_Open()
Range("A1").NumberFormat = "mm/dd/yy hh:mm:ss"
Call Clock
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
ActiveWorkbook.Saved = True
End Sub

Put in a normal module :-

Dim Timer As Date

Sub Clock()
Timer = Now + TimeValue("00:00:01")
Application.OnTime Timer, "Update"
End Sub

Sub Update()
Range("A1").Value = Now
Call Clock
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=Timer, Procedure:="Update", Schedule:=False
End Sub

If you want to look into this further, have a look at "active_clock.zip" at :-
http://www.xl-logic.com/pages/vba.html
 
Upvote 0
Asked for more instructions by PM:

1) Hit Alt + F11 (to open the VB editor).
2) Go to inster | module
3) Paste the following in the window that has just opened:

Code:
Dim stopit As Boolean 'on top of module!

Sub startclock() 'assign start button
  stopit = False
  clock
End Sub

Sub clock()
  If stopit = True Then Exit Sub
   ActiveWorkbook.Worksheets(1).Cells(1, 1).Value = _
   Format(Now, "hh:mm:ss")
   Application.OnTime (Now + TimeSerial(0, 0, 1)), "clock"
End Sub

Sub stopclock() 'assign stop button
 stopit = True
End Sub

4) Note the following:

"Note the Worksheets(1). This indicates the first worksheet in your workbook. You might want to change that to a specific sheet such as Worksheets("Clock Sheet") or Worksheets("Sheet7") so as to not wipe out any sheet that just happens to have become the first sheet."

5) Run the clock by going to tools | macros | startclock. Stop it by running stop clock. (It would make sense to asisgn these 2 macros to buttons on the sheet).

However, as Ponsonby pointed out, having an effectively continuously running macro will make your cursor flicker. Not clear what improvement this is over, say, the system clock?

Paddy
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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