• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

current date and time

hoomantt

Member
hi dear professors;
i have a vb code in my file that when a user click on a shape that code runs.
i need a vb code or a formula that when that user click on that shape and run that code , input current date in a cell and input current time in an other cell .
please help me!!!
Thanks a lot
 
Hi hoomantt,

Try below code:

Code:
Sub enterDateandTime()

Dim CurrentDate As Date
Dim Idate As Date
Dim Itime As Long

CurrentDate = Now
Idate = Int(CurrentDate)
Itime = CurrentDate - Idate

Range("A1") = Idate
Range("B1") = Format(Itime, "hh:mm:ss")

End Sub

Regards,
 
Just add these two lines in your vb code!!!

Code:
Sheet2.[A1] = Date 'Change Range
Sheet2.[B1] = Format(Now, "hh:mm:ss") 'Change Range
 
Back
Top