Command Button Date/Time Stamp

G

Guest

I am trying to date/time stamp a cell by clicking a command button. I want
the cell to display the date and time when the button was last clicked. I can
get it to display the date but I cannot figure out how to get "SendKeys" to
allow me to select CTL+; "SPACE" CTL+ALT+; . This is what I have now as a
command for the button and it will give me a date in the selected cell:

Private Sub CommandButton1_Click()
Range("c2").Select
SendKeys "^(;)"
End Sub
 
N

Norman Jones

Hi Sky,

Try:

'=============>>
Private Sub CommandButton1_Click()
ActiveCell.Value = Format(Now, "mm/dd/yy hh-mm")
End Sub
'<<=============
 
G

Guest

Thanks Guys
I finally also came up with my own less elegant one.
===========
Private Sub CommandButton1_Click()
Range("c2").Select
SendKeys "^(;)"
SendKeys " "
SendKeys "^+(;)", Wait
End Sub
=========
skyknight
 
N

Norman Jones

Hi Sky,
I finally also came up with my own less elegant one.

Elegance is in the eye of the beholder, but why use a clunky implementation
of SendKeys when a native function is available?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top