Excel: How to insert current time (static) to the nearest second?
Option Explicit
Sub Auto_Open()
Application.OnKey "+^:", "'" & ThisWorkbook.Name & "'!Nowtime"
End Sub
Sub Auto_Close()
Application.OnKey "+^:"
End Sub
Sub NOWTIME()
ActiveCell.Value = Format(Now(), "h:mm:ss AM/PM")
End Sub
My version of NowTime looks more like:
Sub NOWTIME()
On Error Resume Next
With Selection
.Value = Now
.NumberFormat = "hh:mm:ss"
End With
If Err.Number < 0 Then
Beep
End If
End Sub
So I can fill multiple cells.
Gord Dibben wrote:
Note: you can't assign it to CTRL + SHIFT + ;
Gord Dibben MS Excel MVP
On Wed, 09 May 2007 18:31:50 -0700, Gord Dibben <gorddibbATshawDOTca wrote:
That method will give you the static time but only to the minute.
To the second, use this macro and assign it to the shortcut combo or a button.
Sub NOWTIME()
ActiveCell.Value = Format(Now(), "h:mm:ss AM/PM")
End Sub
Gord Dibben MS Excel MVP
On Wed, 9 May 2007 12:49:01 -0700, gwm wrote:
When inserting the current time you press CTRL + SHIFT + ; and it displays it
in hours and minutes only. By formatting the cell to display seconds, it will
give 00 seconds rather than more specific time to the nearest second. Can
this function be adjusted to be more precise and display time to the nearest
second rather than just the nearest minute? Note: The "=NOW()" function does
display time to the nearest second, but I cannot use it in this case because
it is not static (i.e. updates).
--
Dave Peterson
|