Sub test()
Dim a, i As Long, ii As Long, b() As String, n As Long, x, temp
With Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(, 4)
a = .Value
ReDim b(1 To UBound(a, 1), 1 To 5)
With CreateObject("VBScript.RegExp")
.Global = True
On Error Resume Next
For i = 1 To UBound(a, 1)
If a(i, 1) <> "" Then
.Pattern = "\.pdf"
a(i, 1) = .Replace(a(i, 1), "")
.Pattern = "00"
a(i, 1) = .Replace(a(i, 1), "0")
.Pattern = "(.+)(?:[_\-])(\d{1,2})(\d{1,2})(\d{4}|\d{2}) (.*)$"
If .test(a(i, 1)) Then
b(i, 4) = CDate(.Replace(a(i, 1), "$4/$2/$3"))
b(i, 5) = Trim$(.Replace(a(i, 1), "$5"))
temp = .Replace(a(i, 1), "$1")
.Pattern = "[^_]+"
For ii = 0 To .Execute(temp).Count
b(i, ii + 1) = .Execute(temp)(ii)
Next
Else
.Pattern = "(.+)(?:[_\-])(\d{1,2})(\d{1,2})(\d{2|\d{4})\d?"
If .test(a(i, 1)) Then
temp = .Replace(a(i, 1), "$4/$2/$3")
b(i, 4) = CDate(.Replace(a(i, 1), "$4/$2/$3"))
temp = .Replace(a(i, 1), "$1")
.Pattern = "(\d+)[_\-](\D+)[_\-](\d+)"
For ii = 1 To 3
b(i, ii) = .Replace(temp, "$" & ii)
Next
b(i, 5) = Trim$(a(i, 2) + a(i, 3) & " " & a(i, 4))
End If
End If
temp = ""
End If
Next
End With
With .Offset(, .Columns.Count + 2).Resize(, 5)
.Value = b
With .Columns(4)
.NumberFormat = "mmddyyyy"
.Value = .Value
End With
End With
End With
End Sub
Bookmarks