Professional Documents
Culture Documents
PR-I-04 (Version 1)
1. Build Digital Clock Through Excel VBA and TEXT Function
In our first method, we will thoroughly use the TEXT function and Excel VBA to build a digital clock with an
automatic refresh. We will insert a VBA code that will
generate the current time in our dataset and the text function will convert the time into text formats and
display it in our clock. Follow the below steps carefully to do so.
Steps:
First, go to Insert > Illustrations > Shapes tabs.
See the below picture to understand better.
PR-I-04 (Version 1)
Eventually, the Shapes menu options box will pop up.
Here, select the Rounded Rectangular option.
PR-I-04 (Version 1)
As a result, a rounded rectangular shape appears in our workbook.
PR-I-04 (Version 1)
Afterward, go to the Developer tab and click Visual Basic.
PR-I-04 (Version 1)
Later, in the module box, write the following VBA code.
Sub Digi_Clock()
Range("B5") = Not Range("B5")
Do While Range("B5") = True
DoEvents
Range("B6") = Now()
Loop
End Sub
Copy
PR-I-04 (Version 1)
Next, in cell B4, type TRUE and hit the Enter or Tab keys.
PR-I-04 (Version 1)
Further, right-click on the rounded rectangle.
PR-I-04 (Version 1)
This converts the time in cell B6 and returns a time format in hh:mm:ss format.
Lastly, press the Enter key again.
In the end, go to the Home tab and then the Font group.
There, customize the font color, size & style.
PR-I-04 (Version 1)
PR-I-04 (Version 1)