Laufzeitfehler '91'
07.01.2022 13:25:15
Max
Option Explicit
Dim regex As Object
Sub ProcessRanges()
Dim cell As Range, result As String
Set regex = CreateObject("vbscript.regexp")
regex.Pattern = "^(0?[1-9]|[1-2][0-9]|3[0-1])(0[1-9]|1[0-2])(19[0-9][0-9]|[2-9]\d{3})$"
With ActiveSheet
For Each cell In .Range("C2:C" & .Cells(Rows.Count, "C").End(xlUp).Row)
FormatDate cell
Next
End With
Set regex = Nothing
End Sub
Sub FormatDate(rngCell As Range)
Dim result As Date
If regex.test(rngCell.Text) Then
result = regex.Replace(rngCell.Text, "$1.$2.$3")
rngCell.NumberFormatLocal = "TT.MM.JJJJ"
rngCell.Value = CDate(result)
End If
End Sub