The VBA Hour Function returns the hour component of a supplied time. The syntax of the function is:
A simple example of the VBA Hour function is shown below:
' Extract the hour component from the time "17:56:33"
Const currTime = "17:56:33"
Dim hourNum As Integer
hourNum = Hour(currTime)' The variable hourNum is now equal to 17.
After running the above VBA code, the variable hourNum holds the value 17, which is the hour component of the supplied time "17:56:33".
If the VBA Hour function is supplied with a value that cannot be interpreted as a valid time, it will return the error: