VBA HOUR Function

HomeVBA Functions LIST (Category Wise)How to use the VBA HOUR Function (Syntax + Example)

What is VBA HOUR Function

how to use it

To use VBA's HOUR function you need to understand its syntax and arguments:




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

Example to use HOUR Function in VBA

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

Sub example_HOUR()
Range("B1").Value = Hour(Range("A1"))
End Sub

In the above code, we have used HOUR to get the hour value from the time which we have in the cell A1 and it has returned 10 in the cell B1 as the time we have in the cell A1 is 10:34:45 AM.


Below are some important points which you need to take care while using HOUR function in VBA.

  • 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.
  • If TIME is NULL, it will return NULL in the result.

Related Functions

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.