How To Show The time in hh:mm.sss format using VBA in Excel?
Tags: toshowthetimeinhhmms, vbamacros
Published: 2021-10-05 02:49:19

---
title: How To Show The time in hh:mm.sss format using VBA in Excel?
published: true
date: 2021-10-04 10:03:40 UTC
tags: ToShowTheTimeInHhmmS,VBAMacros
canonical_url: https://geekexcel.com/how-to-show-the-time-in-hhmm-sss-format-using-vba-in-excel/
---

In this tutorial, we will guide you on how to  **show the time in Hh:mm.Sss format using VBA** in Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to  **create a sample data**  with  **time values in column A**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data-9.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit
Function HHMMSSSFormat(DateTime As Date) As String
'function will return string value
'Declaring integer variable
Dim SecondValue As Integer
'Extracting seconds from DateTime parameter
SecondValue = Second(DateTime)
'Converting seconds value to three digit number
SecondValue = (SecondValue / 60) * 1000
'Change the formatting of time in the required format
HHMMSSSFormat = Format(Hour(DateTime), "00") & ":" & _
   Format(Minute(DateTime), "00") & "." & Format(SecondValue, "000")
End Function
Sub GettingCurrentTimeinHHMMSSSFormat()
'Declaring string variable
Dim CurrentTime As String
'Calling custom function HHMMSSSFormat
CurrentTime = HHMMSSSFormat(Now)
'Displaying message box with Ok button only
MsgBox CurrentTime, vbOKOnly, "Current Time"
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code-8.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/10/Run-the-Code-8.png)<figcaption>Run the Code</figcaption>

- Now, you will receive  **output as time in hh:mm.sss format**  in the Excel sheet as given below.

![](https://geekexcel.com/wp-content/uploads/2021/10/Output-6.png)<figcaption>Output</figcaption>

- Finally, you have also created a **“GettingCurrentTimeinHHMMSSSFo** rmat” macro, which uses the **“HHMMSSSFormat” functio** n to display the **current time in hh:mm.sss format in a message box**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Output1.png)<figcaption>Output in Message Box</figcaption>

## Verdict

We hope that this tutorial gives you guidelines on how to  **show the time in Hh:mm.Sss format using VBA** in Excel. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Read Next:**

- **[Change the Time Format in Excel Office 365 ~ Useful Guide!!](https://geekexcel.com/change-the-time-format-in-excel/)**
- **[How to use Excel TIME Function in Office 365? – With Examples](https://geekexcel.com/how-to-use-time-function-in-excel-365/)**
- **[How to use Excel TEXT Function in Office 365?](https://geekexcel.com/how-to-use-text-function-in-microsoft-excel-365/)**
- **[How to Format Cells in Microsoft Excel 2007?](https://geekexcel.com/how-to-format-cells-in-microsoft-excel-2007/)**
- **[Excel Formulas to Extract the Time from Date and Time ~ Quick Method!!](https://geekexcel.com/excel-formulas-to-extract-the-time-from-date-and-time/)**