wie kann ich prüfen, ob in einer Zelle ein Datum in einem bestimmten Format eingetragen ist?
Bsp.
If IsDate(Range("A1")) Then'im Format TT.MM.JJJJ ist ok
MsgBox "Datum ist korrekt erfasst."
Else
MsgBox "Datum hat das falsche Format"
End If
Sub a()
Dim c As Range: Set c = Range("A1")
If c.NumberFormatLocal Like "TT.MM.JJJJ" Then
MsgBox "Datum OK!"
Else: MsgBox "Datum Nicht-OK!"
End If
End Sub
LG
=ZELLE("Format";A1)
kannst Du dir das Format aus Zelle A1 ausgeben lassen. Das kurze Datumsformat z.b. hat den WErt D2Sub Beispiel()
If IsDate(Range("A1")) Then
If Range("A1").Text = Format(Range("A1").Text, "dd.mm.yyyy") Then
MsgBox "ok"
Else: MsgBox "nicht i.O."
End If
Else: MsgBox "nicht i.O"
End If
End Sub
If IsDate(Range("A1").Value) AND Range("A1").Value like "##.##.####"
oder du nimmst
If IsDate(Range("A1").Text) AND Range("A1").Text like "##.##.####"
das sollte in beiden Fällen funktionieren.