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 by supplying hours, minutes, and seconds.
Syntax
TimeSerial(Hour, Minute, Second)
Arguments
- 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.
Example
To practically understand how to use the 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 cell A1.
Notes
- TIMESERIAL can accept values outside the normal range. If you specify 61 minutes it will add 1 hour to the 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.
More Tutorials
⇠ Back to VBA Function List | What is VBA in Excel
Helpful Links – Developer Tab – Visual Basic Editor – Run a Macro – Personal Macro Workbook – Excel Macro Recorder – VBA Interview Questions – VBA Codes