AW: String in Datum umwandeln
26.01.2018 08:58:13
fcs
Hallo Michael,
hier ein kleines Beispiel
Sub Datums_Umwandlung()
Dim strDatum As String, varDatum As Variant
Dim Zeile As Long
For Zeile = 7 To 9
strDatum = Cells(Zeile, 2).Text
varDatum = Null
'Umwandlung Zelltext in ISO-Datum (Format = YYYY-MM-DD)
strDatum = Replace(strDatum, ".", "-") & "-01"
If IsDate(strDatum) Then
varDatum = CDate(strDatum)
End If
'Ermitteltes Datum weiterverarbeiten
With Cells(Zeile, 2)
If IsNull(varDatum) Then
.Offset(0, 1).ClearContents
MsgBox "Wert """ & .Text & """ in Zelle """ _
& Cells(Zeile, 2).Address(False, False, xlA1) & """ liefert kein gültiges Datum"
Else
.Offset(0, 1).Value = varDatum
MsgBox "Datum in Zelle """ & Cells(Zeile, 2).Address(False, False, xlA1) _
& """ : " & Format(varDatum, "DD.MM.YYYY")
End If
End With
Next
End Sub
Gruß
Franz