What is VBA TIMEVALUE Function
The VBA TIMEVALUE function is listed under the time category of VBA functions. When you use it in a VBA code, it returns a valid time value from the string which represents the date and time or time. In simple words, with TIMEVALUE, you can convert a time that is stored as a text into a valid VBA time.
how to use it
To use VBA's TIMEVALUE function you need to understand its syntax and arguments:
- Time: A string that represents a valid time as per VBA.
Example to use TIMEVALUE Function in VBA
To practically understand how to use VBA TIMEVALUE function, you need to go through the below example where we have written a vba code by using it:
Sub example_TIMEVALUE() Range("B1").Value = TimeValue(Range("A1")) End Sub
In the above code, we have used the TIMEVALUE to get the time value which we have in the cell A1. Basically, there is a date with time and TIMEVALUE returned the time only.
Below are some important points which you need to take care while using TIMEVALUE function in VBA.
- It recognizes both types of time 12-Hours and 24-Hours ("5:27 PM" and "17:27").
- If the time specified is a value other than a time or a string that can’t be recognized as a time, VBA will return the run-time 13 error.
About the Author
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 ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.