VBA Function: TimeValue

The VBA TimeValue function converts a string to a time value, accepting different time formats.

Usage:

TimeValue(text)


Example of Usage

Using the TimeValue function to convert different strings to time:

Sub example()
    
    MsgBox TimeValue("17:30") 'Returns: 5:30:00 PM
    MsgBox TimeValue("17:30:00") 'Returns: 5:30:00 PM
    
    MsgBox TimeValue("05:30:00 PM") 'Returns: 5:30:00 PM
    MsgBox TimeValue("5:30PM") 'Returns: 5:30:00 PM
    
    MsgBox TimeValue("10/31/2024 17:30:00") 'Returns: 5:30:00 PM
    MsgBox TimeValue("Oct 31 2024 17:30") 'Returns: 5:30:00 PM
    
End Sub

In this example, the TimeValue function returns the same time with all the strings.