1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Option Explicit
Sub ModifDate()
Dim oRng As Range
Dim i As Long
With Worksheets("Extract PMV_Transf")
Set oRng = .Range("J2")
For i = 0 To Application.WorksheetFunction.Max(.Cells(.Rows.Count, "J").End(xlUp).Row, .Cells(.Rows.Count, "K").End(xlUp).Row) - oRng.Row
If oRng.Offset(i, 0) <> "" Then
oRng.Offset(i, 3) = oTransform(oRng.Offset(i, 0))
End If
If oRng.Offset(i, 1) <> "" Then
oRng.Offset(i, 4) = oTransform(oRng.Offset(i, 1))
End If
Next i
End With
End Sub
Function oTransform(oDate As String)
Dim oMonth As Integer
Dim oTest As String
Dim EngMonth As Variant
EngMonth = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
If InStr(oDate, "-") Then
oTest = Mid(oDate, InStr(oDate, "-") + 1, 3)
oMonth = Application.Match(oTest, EngMonth, False)
If IsDate(CDate(Left(oDate, 2) & "/" & oMonth & "/" & Mid(oDate, 8, 2))) Then
oTransform = DateSerial(Mid(oDate, 8, 2), oMonth, Left(oDate, 2))
Else
oTransform = "ERREUR"
End If
ElseIf IsNumeric(oDate) Then
oTransform = Format(CDate(oDate), "dd/mm/yyyy")
End If
End Function |
Partager