Вы пытались использовать оператор Like
? Это позволяет проверять числовые значения в каждой позиции символа. Я бы сделал это так:
Function FormatCheck(ByVal strEntered As String)
Dim correctformat As Boolean
If strEntered Like "*#:##" And IsNumeric(Mid(strEntered, 1, InStr(1, strEntered, ":", 1) - 1)) Then
If Mid(strEntered, InStr(1, strEntered, ":", 1) + 1, 999) <= 59 Then
correctformat = True
End If
End If
If Not correctformat Then FormatCheck = "Incorrect format"
End Function
Для этого требуется хотя бы одно число перед ":"
![Testing](https://i.stack.imgur.com/O2zeb.png)
Редактировать: Ниже приведена версия Sub
вместо использования Function
. Появится MsgBox
, как вы использовали изначально. Вы могли бы, вероятно, заменить всю вашу сабвуфер FormatHHMM
без каких-либо отрицательных последствий.
Sub FormatCheck(ByVal strEntered As String)
Dim correctformat As Boolean
If strEntered Like "*#:##" And IsNumeric(Mid(strEntered, 1, InStr(1, strEntered, ":", 1) - 1)) Then
If Mid(strEntered, InStr(1, strEntered, ":", 1) + 1, 999) <= 59 Then
correctformat = True
End If
End If
If Not correctformat Then MsgBox "Incorrect format"
End Sub