Numéro de sécurité sociale
Comment vérifier ou calculer une clef de sécurité sociale (française) en VBA ?
Voici une fonction qui peut faire l’affaire (à recopier dans un module standard) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
' --- ' CALCUL D'UNE CLEF DE SECURITE SOCIALE FRANCAISE ' --- ' Input : strNumero <- 13 premiers caractères du numéro de sécurité sociale ' Output : ClefSecu -> Clef sur 2 chiffres ' #Erreur en cas... d'erreur ' Function ClefSecu(ByVal strNumero As String) As String Dim dblNumero As Double, intReste As Integer ' Le numéro doit comporter 13 chiffres If Len(strNumero) <> 13 Then MsgBox "Le numéro doit comporter 13 chiffres.", vbExclamation ClefSecu = "#Erreur" Exit Function End If ' Conversion en double dblNumero = CDbl(strNumero) ' Calcul du modulo 97 intReste = 97 - (dblNumero - Int(dblNumero / 97) * 97) ClefSecu = Format(intReste, "00") End Function |