Please i have been trying to create a function in VBA to validate time format as hh:mm:ss for a column in my spreadsheet. I am basically trying to ensure that values in this column are in the right format, that is why i am creating a function which i will use in my vlaidation. I will appreciate any help!
I tried this function below last but it is still identifying my time as incorrect.
Function IsTime(x As String) As Boolean
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
' Regex pattern to match time format xx:yy:zz
regex.Pattern = "^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"
' Test the input string against the pattern
IsTime = regex.Test(x)
End Function
anjola olatunbosun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.