• 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.

Digital Clock

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"
 
Last edited:
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!


macro for Digital clock ?
 
Bharath

You questions and comments are only the unintelligible side of brief

Can you please expand on your requirements and I am sure we can help you more
 
Actually i want digital clock in a cell with blinking seconds (running clock) continuously...
i hope u will get
 
Last edited:
Have a look at the File attached below
It has 1 simple macro to drive the update
and one subroutine to start the clock when the worksheet is activated
Blinking isn't a built in option and I wouldn't go to the trouble of coding that using VBA
 

Attachments

  • Simple Clock.xlsm
    15.2 KB · Views: 71
Hi, bharath!

Give a look at the uploaded file. Taking Hui's file as a base, I added a few buttons to avoid having to use my previously suggested method which I assume that you didn't like it.

This is the code for workbook class module:
Code:
Option Explicit

Private Sub Workbook_Open()
    Reset_Clock
End Sub
This for the worksheet Sheet1 class module:
Code:
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
And this for the standard module:
Code:
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

Just advise if any issue.

Regards!
 

Attachments

  • Digital Clock - Simple Clock (for bharath from Hui at chandoo.org).xlsm
    32 KB · Views: 64
Hi, bharath!
Glad you solved it. Thanks for your feedback and for your kind words too. And welcome back whenever needed or wanted.
Regards!
 
Hi all. I know this thread is old but just wanted to say thanks Hui and SirJB7. This thread solved a problem I have had for 2 months. I modified a version of a macro that I found on the Internet to display a live clock. The problem I was having was on closing the workbook, it would open right back up automatically. I am not a macro guru but assume it was because of the "ontime" macro event. This thread solved that. I copied the code which Hui started and SirJB7 added to and tailored it to my needs which was a live clock to run on start up in a specific cell, a button to end the macro so that the workbook would actually close, and a start button to start the live clock in case I want to run the macro after ending it. I am using a data validation list linked to the cell with the live clock to record the start and stop time as I am using this for a time study.

Thanks again. This thread should be saved by all who come across it as there are many people who were/are having the same issue with the workbook not closing.
 
Back
Top