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
Private Sub CommandButton1_Click()
'La variable compteur servira à compter le nbre de tentatives.
Static compteur As Byte
'Gestion des différents prénoms du personnels
Select Case TextBox1.Value
Case "stefan"
compteur = 0
Inscrire TextBox1, TextBox2
Case "virginie"
compteur = 0
Inscrire TextBox1, TextBox2
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
End Sub
Private Sub Inscrire(Quoi, VersCol)
Dim Ligne
On Error GoTo Inscrire_Err_01
With Sheets("Feuil1")
If IsNumeric(VersCol) Then
Ligne = .Cells(.Rows.Count, VersCol).End(xlUp).Row
If .Cells(Ligne, VersCol) <> "" Then Ligne = Ligne + 1
.Cells(Ligne, VersCol) = Quoi
Else
Ligne = .Range(VersCol & .Rows.Count).End(xlUp).Row
If .Range(VersCol & Ligne) <> "" Then Ligne = Ligne + 1
.Range(VersCol & Ligne) = Quoi
End If
Exit Sub
End With
Inscrire_Err_01:
MsgBox "Erreur: """ & VersCol & """ n'est sans doute pas une référence de colonne valide"
End Sub
dl = IIf(.Cells(1, col).Value = "", 1, .Cells(Application.Rows.Count, col).End(xlUp).Row + 1)
If .Cells(1, Col).Value = "" Then
dl = 1
Else
dl = .Cells(Application.Rows.Count, col).End(xlUp).Row + 1
Endif
dl = .Cells(Application.Rows.Count, col).End(xlUp).Row + 1