The VBA TimeValue Function

Related Function:
VBA DateValue

Description

The VBA TimeValue Function returns a VBA Time from a supplied String representation of a time (or date and time). Date information within the supplied string is ignored.

The syntax of the function is:

TimeValue( Time )

Where the Time argument is a valid String representation of a time.


VBA TimeValue Function Examples

' Convert two supplied strings into times
Dim time1 As Date
Dim time2 As Date
time1 = TimeValue( "20:30:45" )
' time1 is now equal to the time 8:30:45 PM
time2 = TimeValue( "1/1/2016 3:00 AM" )
' time2 is now equal to the time 3:00:00 AM

In the above VBA code:


VBA TimeValue Function Error

If the Time that is supplied to the TimeValue function cannot be converted to a valid date/time, you will get the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box