Function testDate(Cellule As Range, Rang As Integer) As String
'Application.Volatile
Dim oRexp, Match, Matches, MesMois, MesMoisBis, I As Integer, MaChaine As String, Jour As Long, An As Long
If Cellule = "" Then Exit Function
MesMois = Array("janvier", "janv.", "janv", "février", "févr.", "févr", "fevrier", "fevr.", "fevr", _
"mars", "avril", "avr.", " avr ", "mai", "juin", _
"juillet", "juil.", "juil", "août", "aout", "septembre", "sept.", _
"sept", "octobre", "oct.", "oct", "novembre", "nov.", "nov", "décembre", "déc.", "déc", "decembre", "dec.", "dec")
MesMoisBis = Array("/01/", "/01/", "/01/", "/02/", "/02/", "/02/", "/02/", "/02/", "/02/", _
"/03/", "/04/", "/04/", "/04/", "/05/", _
"/06/", "/07/", "/07/", "/07/", "/08/", "/08/", "/09/", "/09/", _
"/09/", "/10/", "/10/", "/10/", "/11/", "/11/", "/11/", "/12/", "/12/", "/12/", "/12/", "/12/", "/12/")
MaChaine = LCase(Cellule.Value)
For I = LBound(MesMois) To UBound(MesMois) 'traitement du mois
If InStr(1, Cellule.Value, MesMois(I), vbTextCompare) > 0 Then
MaChaine = Trim(Replace(MaChaine, MesMois(I), MesMoisBis(I)))
MaChaine = Replace(Replace(MaChaine, " /", "/"), "/ ", "/")
End If
Next I
Set oRexp = CreateObject("vbscript.regexp")
With oRexp
.Global = True
.IgnoreCase = True
'traitement du jour
.Pattern = "(?:\s|\b)(\d{1})([ /-]\d{1,2}[ /-])(\d{2,4})(?:\s|\b)"
Set Matches = .Execute(MaChaine)
MaChaine = .Replace(MaChaine, " 0$1$2$3 ")
'traitement de l'année
.Pattern = "(?:\s|\b)(\d{1,2})([ /-]\d{1,2}[ /-])((?:0|1|2){1}[0-9])(?:\s|\b)" 'années 2000 à 2 chiffres
Set Matches = .Execute(MaChaine)
MaChaine = .Replace(MaChaine, " $1$220$3 ")
.Pattern = "(?:\s|\b)(\d{1,2})([ /-]\d{1,2}[ /-])((?:3|4|5|6|7|8|9){1}[0-9])(?:\s|\b)" 'années 1900 à 2 chiffres
Set Matches = .Execute(MaChaine)
MaChaine = .Replace(MaChaine, " $1$219$3 ")
.Pattern = "((0[1-9]|[12]\d|3[01])[ /-](0?[13578]|1[02])|(0[1-9]|[12]\d|30)[ /-](0?[469]|11))[ /-]((16|17|18|19|20|21)\d\d)|(0[1-9]|[1]\d|[2][0-8])[ /-]0?2[ /-]((16|17|18|19|20|21)\d\d)|29[ /-]0?2[ /-]((190|210)[48]|(17|18|19|20|21)([13579][26]|[2468][048])|(160|200)[048])"
If .test(MaChaine) = True Then
Set Matches = .Execute(MaChaine)
If Rang - 1 < Matches.Count Then testDate = Format(Matches(Rang - 1), "dd/mm/yyyy")
Else
If Rang = 1 Then testDate = "Date non valide"
End If
End With
End Function