Gruppe
DatumZeit
Problem
Wie kann ich wahlweise Texteingaben in eine Zelle im Format HHMM oder HHMMSS in die entsprechenden Zeiten umwandeln lassen?
ClassModule: Tabelle1
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sTxt As String
If Target.Column < 5 Or Target.Column > 6 Then Exit Sub
If IsEmpty(Target) Or Selection.Cells.Count > 1 Then Exit Sub
sTxt = CStr(Target.Value)
Select Case Len(sTxt)
Case 3: sTxt = "0" & sTxt & "00"
Case 4: sTxt = sTxt & "00"
Case 5: sTxt = "0" & sTxt
End Select
sTxt = Left(sTxt, 2) & ":" & Mid(sTxt, 3, 2) & ":" & Right(sTxt, 2)
On Error GoTo ERRORHANDLER
Application.EnableEvents = False
Target.Value = TimeValue(sTxt)
Application.EnableEvents = True
Exit Sub
ERRORHANDLER:
ActiveCell.ClearContents
Application.EnableEvents = True
End Sub