×

VBA TimeSerial Function

The TimeSerial function in VBA returns a Time for the specified hour, minute, and second.

Syntax

TimeSerial (Hour, Minute, Second)

Parameter

Hour (required) – This parameter represents an integer (0 to 23), signifying the hour of the time.

Minute (required) – This parameter represents an integer (0 to 59), signifying the minute of the time. If it is less than 0 or greater than 59, this value is subtracted from, or added to, the specified number of hours.

Second (required) – This parameter represents an integer (0 to 59) representing the second of the time. If it is less than 0 or greater than 59, this value is subtracted from, or added to, the specified number of minutes.

Return

This function returns a Time for the given hour, minute, and second.

Example 1

Sub TimeSerialFunction_Example1()
 ' It will return the time dor given hour, minute, second
 Dim time_val As Date
 Dim hour_val As Integer, minute_val As Integer, second_val As Integer
 hour_val = 9 
 minute_val = 56
 second_val = 45
 'calculating the time based on above values
 time_val = TimeSerial(hour_val, minute_val, second_val) 
 ' The variable time_val will rteurn a time value 9:56:45 AM.
 Cells(1, 1).Value = time_val
 End Sub 

Output

9:56:45 AM

VBA TimeSerial Function

Example 2

Sub TimeSerialFunction_Example2()
 ' It will return the time dor given hour, minute, second
 Dim time_val As Date
 Dim hour_val As Integer, minute_val As Integer, second_val As Integer
 hour_val = 9
 'when the supplied Minute or Second argument is outside the range 0 - 59. 
 minute_val = -1
 second_val = 45
 'calculating the time based on above values
 time_val = TimeSerial(hour_val, minute_val, second_val)
 ' The variable time_val will rteurn a time value 9:56:45 AM.
 Cells(1, 1).Value = time_val
 End Sub 

Output

8:59:45 AM

VBA TimeSerial Function

Example 3

Sub TimeSerialFunction_Example3()
 ' It will return the time dor given hour, minute, second
 Dim time_val As Date
 Dim hour_val As Integer, minute_val As Integer, second_val As Integer
 hour_val = 9
 minute_val = 0 
 second_val = 60
 'calculating the time based on above values
 time_val = TimeSerial(hour_val, minute_val, second_val) 
 ' The variable time_val will rteurn a time value 9:01:00 AM.
 Cells(1, 1).Value = time_val
 End Sub 

Output

9:01:00 AM

VBA TimeSerial Function

Related Topics

Excel VBA: DO WHILE….Loop

DO WHILE….Loop The “Do While” Loop is the same, unlike the FOR statement, just that it will keep on looping till the specified condition is true. It is used when we want to...

3 minutes read.

Excel VBA DateSerial Function

The DateSerial function in VBA returns a Date from a supplied year, month, and day number. Syntax DateSerial (Year, Month, Day) Parameter Year (required) – This parameter represents an integer signifying the year. Month (required) – This parameter...

2 minutes read.

Excel VBA CCur Function

The CCur function in VBA is used to convert an expression into a Currency data type. It can take a maximum of 15 digits to the left of the decimal place and...

1 minute read.

VBA Object Required

What is Object Required Error? VBA Object Required is a run time error which occurs when the user does not define a valid object qualifier, or the assigned object doesn’t exist in the...

6 minutes read.

Excel VBA Asc Function

VBA Asc Function: The Asc function in VBA returns an integer showing the character code for the first character of a given string. Syntax Asc (String) Parameter String (required) – This parameter represents the text...

1 minute read.

Excel VBA InStrRev Function

VBA InStrRev Function: The InStrRev function in Excel VBA returns an integer representing the position of a substring within the specified string if the substring is fount else it returns...

2 minutes read.

Excel VBA FormatNumber Function

VBA FormatNumber Function: The FormatNumber function in VBA is used to apply a number format to a numeric expression, and it returns the result as a string. Syntax FormatNumber (Expression, [NumDigitsAfterDecimal], [IncludeLeadingDigit], [UseParensForNegativeNumbers], [GroupDigits]) Parameter Expression (required)...

2 minutes read.

Excel VBA Second Function

Excel VBA Second Function: The Second function in VBA returns the second element for the specified time.  Syntax Second (Time) Parameter Time (required) – This parameter represents the time. Return This function returns the second...

1 minute read.

Excel Objects in VBA

What are Excel Objects? The Excel objects belong to the entities that make up an Excel Workbook, Worksheets, Columns, Rows, Cell Ranges, etc. Each object in Excel has loads of Properties that are...

6 minutes read.

Excel VBA- Pivot Table Fields

VBA- Pivot Table Fields: The Pivot Fields collection contains all the fields from the data source, including any calculated fields. The main aspect of adding a field is its Position...

4 minutes read.

Excel VBA IsMissing Function

VBA IsMissing Function: The IsMissing function in VBA checks if any parameter to a procedure is missing or not. It returns a Boolean value True if the specified parameter has not been...

1 minute read.

Excel VBA CVar Function

VBA CVar Function: The CVar function in VBA converts an expression into a Variant data type. Syntax CVar (Expression) Parameter Expression (required) – This parameter represents the expression that that you want to convert...

1 minute read.

VBA Regex Pattern Validation

VBA Regex Pattern Validation The key purpose of using Regex in VBA was to validate the data and extract the same category of data. There are certain formats that are standard...

6 minutes read.

Excel VBA Choose Function

VBA Choose Function: The Choose function in VBA chooses function selects the corresponding value from a list of arguments depending as per the specified index. Syntax Choose (Index, [Choice-1], [Choice-2], ...) Parameter Index (required) – This...

2 minutes read.

Excel VBA Year Function

Excel VBA Year Function: The Year function in VBA returns the four-digit year for the specified date. Syntax Year (Date) Parameter Date (required) – This parameter represents the significant date. Return This function returns the four-digit year...

1 minute read.

For Next loop in VBA

For Next Loop The ”For Next” loop is used for a fixed number of times. It works by implementing the loop for the specified number of times. In this, the user specifies how...

3 minutes read.

VBA UBound

VBA UBound  The UBound or Upper Bound function in VBA is used to specify the length of an array and returns the highest subscript for a dimension for the specified array. It is...

3 minutes read.

VBA Screen Updating

What is VBA Screen Updating property? Screen Updating is a VBA property which is used to display the output generation while running the code. If this property is enabled, we could see...

6 minutes read.

VBA ListBox

What is a ListBox? ListBox refers to a permanently displayed control (usually box-shaped) which contains a list of objects (or attribute, or elements) from which the user can select single or multiple attributes....

8 minutes read.

Excel VBA Oct Function

VBA Oct Function: The Oct function in VBA converts the given number into octal notation and returns the result as a string. Syntax Oct (Number) Parameter Number (required) – This parameter represents the numeric value...

1 minute read.