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:
Where the Time argument is a valid String representation of a time.
' Convert two supplied strings into times
Dim time1 As Date
Dim time2 As Date
time1 = TimeValue( "20:30:45" )time2 = TimeValue( "1/1/2016 3:00 AM" )
' time1 is now equal to the time 8:30:45 PM
' time2 is now equal to the time 3:00:00 AM
In the above VBA code:
If the Time that is supplied to the TimeValue function cannot be converted to a valid date/time, you will get the error: