VBA SECOND Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA SECOND function is listed under the time category of VBA functions. When you use it in a VBA code, it can get a seconds value from a valid time value as per VBA. As you know a valid VBA time is made up of hours, minutes, and seconds so it takes a second and ignores the rest of the part. It’s just like the SECONDS function in the worksheet.

Syntax

Second(Time)

Arguments

  • Time: A valid time as per VBA from which you want to get the seconds value.

Example

To practically understand how to use VBA SECOND function, you need to go through the below example where we have written a vba code by using it:

example-vba-second-function
Sub example_SECOND()
Range("B1").Value = Second(Range("A1"))
End Sub

In the above code, we have used the SECOND function to get the seconds from the time which we have in cell A1 and in the result, it has returned 26.

Notes

  • If the supplied time value is NULL, then it will return NULL.
  • If the value specified is a value other than a valid time or a string that can’t be recognized as a valid time, VBA will return the run-time 13 error.