Time format of text box in excel user form
问题 I have below code to set time format of atext box "txtA" in userform. Private Sub txtA_Afterupdate() Dim tString As String With txtA 'Check if user put in a colon or not If InStr(1, .Value, ":", vbTextCompare) = 0 And Len(.Value) > 1 Then 'If not, make string 4 digits and insert colon tString = Format(.Value, "0000") tString = Left(tString, 2) & ":" & Right(tString, 2) txtA.Value = Format(TimeValue(tString), "hh:mm") Else 'Otherwise, take value as given .Value = Format(.Value, "hh:mm") End If