Dim myTime as Double
myTime=Time
MsgBox "The time is: " & myTtime, vbOKOnly, "The Time"
Hi, bharath!
First of all I assume you've read this (if not I'd say you should and must):
http://chandoo.org/forum/forums/new-users-please-start-here.14/
Second, placing the post n the proper forum: VBA macros, this is Ask an Excel question (it's not serious, I'll move it).
Third following the guidelines of the posting link related to how to expose your problem.
Fourth putting a significant title.
Regards!
In a cell you can type =Now()
Excel will display the Date and Time
You can display the time only by applying a Custom Format of hh:mm:ss AM/PM
To learn more about times have a read of: http://chandoo.org/wp/2013/10/17/excel-date-time-tips/
If you want to return the value in a VBA Macro simply use the =Time function
eg:
Code:Dim myTime as Double myTime=Time MsgBox "The time is: " & myTtime, vbOKOnly, "The Time"
In a cell you can type =Now()
Excel will display the Date and Time
You can display the time only by applying a Custom Format of hh:mm:ss AM/PM
To learn more about times have a read of: http://chandoo.org/wp/2013/10/17/excel-date-time-tips/
If you want to return the value in a VBA Macro simply use the =Time function
eg:
Code:Dim myTime as Double myTime=Time MsgBox "The time is: " & myTtime, vbOKOnly, "The Time"
Hi, bharath!
First of all I assume you've read this (if not I'd say you should and must):
http://chandoo.org/forum/forums/new-users-please-start-here.14/
Second, placing the post n the proper forum: VBA macros, this is Ask an Excel question (it's not serious, I'll move it).
Third following the guidelines of the posting link related to how to expose your problem.
Fourth putting a significant title.
Regards!
Option Explicit
Private Sub Workbook_Open()
Reset_Clock
End Sub
Option Explicit
Private Sub Worksheet_Activate()
Update_Clock
End Sub
Private Sub cmdReset_Click()
Reset_Clock
End Sub
Private Sub cmdEnd_Click()
End_Clock
End Sub
Private Sub cmdStart_Click()
Start_Clock
End Sub
Private Sub cmdStop_Click()
Stop_Clock
End Sub
Option Explicit
Dim tStart As Date, tStop As Date, tElapsed As Date, tNextTime As Date
Sub Reset_Clock()
Update_Clock
Worksheets("Sheet1").[C4:C6].ClearContents
End Sub
Sub End_Clock()
Application.OnTime tNextTime, "Update_Clock", , False
End Sub
Sub Start_Clock()
tStart = Now()
Reset_Clock
With Worksheets("Sheet1")
.[C5].Value = tStart
.[C5].NumberFormat = .[C2].NumberFormat
End With
End Sub
Sub Stop_Clock()
tStop = Now()
tElapsed = tStop - tStart
With Worksheets("Sheet1")
.[C6].Value = tStop
.[C6].NumberFormat = .[C2].NumberFormat
.[C4].Value = tElapsed
End With
End Sub
Function Update_Clock()
Calculate
tNextTime = Now() + TimeValue("0:0:1")
Application.OnTime tNextTime, "Update_Clock"
End Function