Private Sub CommandButton1_Click()
Dim Id32, Id160, col&, indexTS&, Ligne&
Id32 = Application.Trim(TxtNoId)
If Not Id32 Like "### ### ### ### ###" Then ' vérification du bon format de l'Id
' le format n'est pas bon -> information et sortie de la procédure
MsgBox "L'Id de l'animal n'a pas le bon format (5 groupes de 3 chiffres)", vbCritical
Exit Sub
End If
Id160 = Replace(Id32, Chr(32), Chr(160)) ' Id de l'animal à rechercher avec espaces insécables
' recherche de la colonne des IdAnimal au sein de la base (tableau structuré "BD")
' la colonne est le numéro absolu de la colonne (colonne de la feuille "BD")
col = Application.Match("IdAnimal", Worksheets("BD").ListObjects(1).Range.Rows(1).EntireRow, 0)
' on recherche l'Id de l'animal dans la colonne col - si pas trouvé alors on renvoie 0
Ligne = Application.IfError(Application.Match(Id160, Worksheets("BD").Columns(col), 0), 0)
If Ligne = 0 Then ' l'id est absent
MsgBox "Aucune Occurence trouvée"
Else ' l'id est présent
' on retire du N° de la ligne (absolu) - le n° de ligne (absolu) du TS BD (calcul index)
indexTS = Ligne - Worksheets("BD").ListObjects(1).Range.Row
MsgBox "Index = " & indexTS, vbInformation
End If
' à ce stade l'index de l'ID est >>>>> indexTS
End Sub