How to get the time stamp in VBA for EXCEL

J

Ji Wenke

I want to record current time (Hour-Minutes-Second) in
VBA.How to accomplish with VB code,use what system
function call
 
R

Rocky McKinley

Hi Ji,
Try this,

Sub TimeStamper()
Range("A1").Value = Now
Range("A1").NumberFormat = "H:MM AM/PM"
End Sub

Regards, Rocky McKinley
 
M

Michael Bednarek

I want to record current time (Hour-Minutes-Second) in
VBA.How to accomplish with VB code,use what system
function call

I probably misunderstand the question, but doesn't:
Hour(Now) & "-" & Minute(Now) & "-" & Second(Now)
work for you?
(Nit pick: the above might give unexpected results when its execution
straddles midnight.)
 
R

Rocky McKinley

Hi Ji,
Oops should have included ":SS" as below,

Sub TimeStamper()
Range("A1").Value = Now
Range("A1").NumberFormat = "H:MM:SS AM/PM"
End Sub

Regards, Rocky McKinley
 

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