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
End With
Assume I have say 20 text boxes,(A - E) make one group (F- H)make another group and so on. now I have 2 Q. 1-Should i apply above code to each textbox individually or there's a code that i just can put all text boxes name of userform in it? 2- with input data higher than 23:59 it gives error i changed the format to [h]:mm but didn't work,I want if user enters 35:45 the time be shown as it is not like d:hh:mm