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
| Sub Formater()
Dim Wk As Workbook
Dim Ws As Worksheet
Dim Plage As Range
Set Wk = Workbooks("Classeur1")
Set Ws = Wk.Worksheets("Feuil1")
Set Plage = Ws.Range("A1:A11")
For Each Cel In Plage
Cel.Value = DateFormatee(Cel.Value)
Next
End Sub
Function DateFormatee(Ad As String) As Date
Dim LaDateFormatée As String, i As Byte, LeMois(), j as Byte
LeMois = Array("", "Jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "now", "dec") 'etc
If Trim(Ad) = "" Or IsDate(Ad) Then
DateFormatee = Ad
Exit Function 'La date est en français, on sort avec la date lue
End If
LaDateFormatée = Ad 'je récupère la date en anglais
For i = 1 To Len(LaDateFormatée)
'je vérifie si c'est un chiffre ou un caractère
If Asc(Mid(LaDateFormatée, i, 1)) > 57 Then 'C'est un caractère, je sors
Exit For
End If
Next
For j = 0 To UBound(LeMois) 'recherche dans LeMois le N° du mois anglais
If LCase(LeMois(j)) = LCase(Mid(LaDateFormatée, i, 3)) Then Exit For
Next
'on a le mois (j) on reconstitue la date au format "j/m/a"
LaDateFormatée = Left(LaDateFormatée, i - 1) & "/" & j & "/" & Mid(LaDateFormatée, i + 3, Len(LaDateFormatée) - i - 2)
'On formate la date au format voulu
DateFormatee = Format(LaDateFormatée, "dd mmm yyyy")
End Function |
Partager