Friday, August 12, 2016

How to use the TIMESERIAL Function (VBA)

Description

The Microsoft Excel TIMESERIAL function returns a time given an hour, minute, and second value.

Syntax

The syntax for the TIMESERIAL function in Microsoft Excel is:
TimeSerial( hour, minute, second )

Parameters or Arguments

hour
A numeric value between 0 and 23 that represents the hour value of the time.
minute
A numeric value that represents the minute value of the time.
second
A numeric value that represents the second value of the time.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The TIMESERIAL function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel TIMESERIAL function examples and explore how to use the TIMESERIAL function in Excel VBA code:
TimeSerial(14, 6, 30)
Result: 2:06:30 PM

TimeSerial(20 - 8, 6, 30)
Result: 12:06:30 PM

TimeSerial(8, 6-2, 14)
Result: 8:04:14 AM

TimeSerial(7, -15, 50)
Result: 6:45:50 AM
For example:
Dim LTime As Date

LTime = TimeSerial (23, 5, 31)
In this example, the variable called LTime would now contain the value of "11:05:31 PM".