The VBA TIMESERIAL function is listed under the time category of VBA functions. When you use it in a VBA code, it returns a valid VBA time as per the hours, minutes, and seconds supplied. In simple words, you can create a time value with it supplying hours, minutes, and seconds.
TimeSerial(Hour, Minute, Second)
- Hour: An integer ranging from 0 to 23 to specify the hours.
- Minute: An integer ranging from 0 to 59 to specify the minutes.
- Second: An integer ranging from 0 to 59 to specify the seconds.
To practically understand how to use VBA TIMESERIAL function, you need to go through the below example where we have written a vba code by using it:
Sub example_TIMESERIAL() Range("A1").Value = TimeSerial(10, 35, 56) End Sub
In the above, we have used the TIMESERIAL to create valid time (as per VBA) by specifying the hours, minutes, and seconds in the function directly and it has returned that time in the cell A1.
- TIMESERIAL can accept values outside the normal range. If you specify 61 minutes it will add 1 hour to hour value and use 1 as the minute value.
- If any argument is outside -32,768 to 32,767, VBA will return the run-time 13 error.