voici ma solution mais elle est encore à améliorer...
salutations à tous!
Function avs_nais(no_avs As Variant) As Date
Dim vAnnee As Integer
Dim vMois As Byte
Dim vJour As Integer
Dim avs3 As Integer
Dim avs2, avs1 As Boolean
'test le format'
If isnumberr(no_avs) = False Then
'format chaîne de caractere'
avs1 = False
ElseIf no_avs - Int(no_avs) = 0 Then
avs1 = True
'format numeric'
Else: avs1 = False
End If
'test sur les points'
If isnumberr(no_avs) = False And isnumberr(mid(no_avs, 4, 1)) = False And isnumberr(mid(no_avs, 7, 1)) = False Then
avs2 = True
'avs2 est un caractère'
Else: avs2 = False
'avs2 est un numéric'
End If
If avs1 = True And avs2 = True Then
avs_nais = "#Error in No_AVS format!"
ElseIf isnumberr(mid(no_avs, 4, 1)) = True Then
avs3 = 1
Else: avs3 = 2
End If
If isnumberr(mid(no_avs, (4 + 2 * avs3), 1)) = 0 Or isnumberr(mid(no_avs, (4 + 2 * avs3), 1)) = 9 Then
avs_naiss = "#Error in No_AVS format!"
End If
vAnnee = mid(no_avs, avs3 + 3, 2)
If mid(no_avs, (4 + 2 * avs3), 1) < 5 Then
vMois = (mid(no_avs, 4 + 2 * avs3, 1) - 1) * 3 + 1 + Int(mid(no_avs, 5 + 2 * avs3, 2) / 31.5)
Else: vMois = (mid(no_avs, 4 + 2 * avs3, 1) - 5) * 3 + 1 + Int(mid(no_avs, 5 + 2 * avs3, 2) / 31.5)
End If
If Modulo(mid(no_avs, 5 + 2 * avs3, 2), 31) = 0 Then
vJour = 31
Else: vJour = Modulo(mid(no_avs, 5 + 2 * avs3, 2), 31)
End If
If avs_nais >= Date Then
avs_nais = 1
Else: avs_nais = DateSerial(vAnnee, vMois, vJour)
End If
End Function