Private Sub CommandButton1_Click()
'La variable compteur servira à compter le nbre de tentatives.
Static compteur As Byte
Dim dl As Long
Dim col As Byte
'Gestion des différents prénoms du personnels
Select Case TextBox1.Value
Case "stefan"
compteur = 0
col = 1
'.Range("B65536").End(xlUp).Offset(1, 0) = Val(UserForm4.TextBox5) 'option Val tranforme du text en nombre
'.Range("C65536" & num).End(xlUp).Offset(1, 0) = CDate(UserForm4.TextBox3) 'cdate & num transforme en nombre date
Case "virginie"
compteur = 0
col = 2
Case Else
MsgBox "inconnu"
compteur = compteur + 1
TextBox1.Value = ""
TextBox1.SetFocus
If compteur = 2 Then
MsgBox "Dernière tentative"
End If
'Si c'est la 3e fois que l'utilisateur entre un nom incorrect,le programme prend fin
If compteur = 3 Then
Unload Me
'ActiveWorkbook.Save
'ActiveWorkbook.Close
End If
End Select
TextBox2.Value = col
With Sheets("Feuil1")
On Error Resume Next
dl = IIf(.Cells(1, col).Value = "", 1, .Cells(Application.Rows.Count, col).End(xlUp).Row + 1)
If Err <> 0 Then Err = 0
.Cells(dl, col).Value = Me.TextBox1.Value
On Error GoTo 0
End With
End Sub