Return to VBA Code Examples

VBA TimeValue Function

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

TimeValue Description

Returns the serial number of a time.

Simple TimeValue Examples

Here is a simple TimeValue example:

Sub TimeValue_Example()
    MsgBox TimeValue("6:30:10")
End Sub

This code will return 6:30:10 AM.

TimeValue Syntax

In the VBA Editor, you can type¬† “TimeValue(” to see the syntax for the TimeValue Function:

The TimeSerial function contains an argument:

Time: A string of text representing a time (ex. “12:00:00 A.M”).

Examples of Excel VBA TimeValue Function

MsgBox TimeValue("6:30")

Result: 6:30:00 AM

MsgBox TimeValue("6:30 PM")

Result: 6:30:00 PM

MsgBox TimeValue("16:30:15")

Result: 4:30:15 PM


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples