While working in Microsoft Excel sometimes we need to create a timer with milliseconds. You can easily do it using VBA in Excel. But sometimes it becomes difficult while create a timer. Today in this article, I am sharing with you how to create a timer with milliseconds in Excel VBA.
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
Steps-by-Step Procedures to Create a Timer with Milliseconds in Excel VBA
In the following, I have explained the step-by-step procedures to create a timer with milliseconds in Excel VBA. To do the task, we will apply VBA code with multiple VBA functions, such as the Format and Timer functions. Later on, we will assign a macro button to show the time in milliseconds.
Step 1: Creating Data Set with Timers
Above all, let’s start with creating a dataset. We will put some time inside the worksheet.
- Just open a workbook and put your desired time in, just like the screenshot below.
Read More: Excel VBA to Create Timer Loop (3 Unique Examples)
Step 2: Applying VBA Code to Convert Time in Milliseconds
In this section, we will write VBA code and save it for further processing.
- Second, we will apply VBA code to convert time into milliseconds.
- Simply, select cells (B5:B12) and click ALT+F11 to open Microsoft Visual Basic for Applications.
- Next, inside the Module place the following code and click on Save.
Sub Timer_Milliseconds() Selection.NumberFormatLocal = "h:mm:ss.000" ActiveCell.Value = Format(Now, "h:mm:ss") & Right(Format(Timer, "0.000"), 4) End Sub
Read More: How to Use Timer Function in Excel VBA (3 Easy Examples)
Step 3: Creating and Assigning a Macro Button
As we have saved our VBA code in the previous step, it’s time for creating a macro button for the code and assigning according to it.
- In this step, we will create and assign a macro button for the code. To do so, choose a Rectangle Shape from the Insert option.
- Then, double-click on the worksheet to create the shape.
- Thereafter, type Timer Milliseconds inside the box.
- Hence, selecting the shape right click to get multiple options. From the options choose Assign Macro.
- After that, select Timer Milliseconds from the Macro Name and press OK.
Read More: How to Delay Timer with VBA in Excel (3 Easy Ways)
Step 4: Generating Final Results
Finally, click the button and you will get your output with a milliseconds timer in your hands. Within a short time, we created a timer with milliseconds in Excel VBA.
Read More: How to Create Timer Event with VBA in Excel (with Easy Steps)
In this article, I have tried to cover almost all the steps to create a timer with milliseconds in Excel VBA. Take a tour of the practice workbook and download the file to practice by yourself. I hope you find it helpful. Please inform us in the comment section about your experience. We, the Exceldemy team, are always responsive to your queries. Stay tuned and keep learning.