View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
PrologPro PrologPro is offline
external usenet poster
 
Posts: 2
Default Entering current date and time

Unfortunately that didn't work. When I run the macro, no value is entered.
I also need to make sure the date and time are static and automatically
entered with a macro (instead of entering today's date and time manually),
which is why I wanted to avoid the NOW formula.

I wish there were a way to record a macro or write VB for the "CTRL + ;"
shortcut...any ideas?

Thanks!

"Dave Peterson" wrote:

You could use something like:

Option Explicit
Sub PutDateTime()
On Error Resume Next
With Selection
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
.Value = Now
End With
If Err.Number < 0 Then
MsgBox "Time not inserted"
Err.Clear
End If
On Error Goto 0
End Sub

If you give it a nice shortcut combo, it might even be easier.

Tools|Macro|macros
select PutDateTime
click options
Change the shortcut key Uppercase T (maybe???)
When you type that uppercase T, the dialog will show
ctrl-shift-T
click ok
click cancel to dismiss the dialog

Try it out.

PrologPro wrote:

I'm trying to come up with the quickest way to enter the current date and
time in my spreadsheet.

So far here's what I've tried:

Macro which recorded CTRL + ; (space) CRTL + SHIFT + ;
Unfortunately if you look at how the macro recorded this static date, it
actually has today's date listed in VB, not the actual function. I just want
VB to perform the FUNCTION.

I also tried the NOW() function, but I will have multiple rows keep track of
patches I've applied, and the date and time will change with each row entry.
The NOW formula updates all rows with the same date and time.

Any suggestions would be greatly appreciated.
Thanks!


--

Dave Peterson