1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
Dim nomrecherche As String
Dim ligne As Long
Private Sub btncreer_Click()
'ici a fin de gagnier du temp et de la memoire j'ai supprimer ta boucle do wile et je les remplacer par la variable i _
dont la valeur prend directement lle numero de la ligne suivante la derniere ligne utilisée
i = Sheets("employes").Cells(Rows.Count, 1).End(xlUp).Row + 1
If T_nom.Value = "" Then ' si le t_nom est vide
MsgBox "Veuillez completer le nom"
Else
'sinon
ThisWorkbook.Sheets("employes").Cells(i, 1) = T_nom
ThisWorkbook.Sheets("employes").Cells(i, 2) = T_prenom
ThisWorkbook.Sheets("employes").Cells(i, 3) = T_fonction
ThisWorkbook.Sheets("employes").Cells(i, 4) = T_matricule
ThisWorkbook.Sheets("employes").Cells(i, 5) = T_datedenaissance
ThisWorkbook.Sheets("employes").Cells(i, 6) = T_adresse
ThisWorkbook.Sheets("employes").Cells(i, 7) = T_codepostal
ThisWorkbook.Sheets("employes").Cells(i, 8) = T_ville
ThisWorkbook.Sheets("employes").Cells(i, 9) = T_pays
ThisWorkbook.Sheets("employes").Cells(i, 10) = T_salairebrutannuel
ThisWorkbook.Sheets("employes").Cells(i, 11) = T_numerodetelephone
ThisWorkbook.Sheets("employes").Cells(i, 12) = T_numerodegsm
ThisWorkbook.Sheets("employes").Cells(i, 13) = T_email
MsgBox "Opération effectuée"
End If
'ici on vide les textboxs pour eviter de reloader le userform comme tu le fesait avant
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then ctrl.Value = ""
Next
End Sub
Private Sub btnmodifier_Click()
Dim objtr As String
Dim q As String
objtr = nomrecherche
If T_nom <> "" Then
'****************************************
With Sheets("employes").Range("a1:a" & Sheets("employes").Cells(Rows.Count, 1).End(xlUp).Row)
Set c = .Find(objtr, LookIn:=xlValues)
If Not c Is Nothing Then q = MsgBox("modifier " & objtr & " ? ", vbCritical + vbYesNo)
If q = vbYes Then
If i = 0 Then i = ligne
ligne = c.Row
ThisWorkbook.Sheets("employes").Cells(i, 1) = T_nom
ThisWorkbook.Sheets("employes").Cells(i, 2) = T_prenom
ThisWorkbook.Sheets("employes").Cells(i, 3) = T_fonction
ThisWorkbook.Sheets("employes").Cells(i, 4) = T_matricule
ThisWorkbook.Sheets("employes").Cells(i, 5) = T_datedenaissance
ThisWorkbook.Sheets("employes").Cells(i, 6) = T_adresse
ThisWorkbook.Sheets("employes").Cells(i, 7) = T_codepostal
ThisWorkbook.Sheets("employes").Cells(i, 8) = T_ville
ThisWorkbook.Sheets("employes").Cells(i, 9) = T_pays
ThisWorkbook.Sheets("employes").Cells(i, 10) = T_salairebrutannuel
ThisWorkbook.Sheets("employes").Cells(i, 11) = T_numerodetelephone
ThisWorkbook.Sheets("employes").Cells(i, 12) = T_numerodegsm
ThisWorkbook.Sheets("employes").Cells(i, 13) = T_email
'***********************************************
End If
End With
End If
nomrecherche = ""
End Sub
Private Sub btnquitter_Click()
Unload Me
End Sub
Private Sub btnrecherche_Click()
If T_nom.Value = "" Then
MsgBox "Veuillez introduire un nom "
Exit Sub
End If
With Sheets("employes").Range("a1:a" & Sheets("employes").Cells(Rows.Count, 1).End(xlUp).Row)
Set c = .Find(T_nom, LookIn:=xlValues)
If Not c Is Nothing Then
Me.SpinButton2 = c.Row
Else
MsgBox "Aucun résultat !" & Chr(10) & "Essayez à nouveau "
End If
btncreer.Enabled = False
nomrecherche = T_nom
End With
End Sub
Private Sub btnsupprimer_Click()
'ici on va faire plus simple et plus rapide que ta boucle do/loop
If T_nom <> "" Then
With Sheets("employes").Range("a2:a" & Sheets("employes").Cells(Rows.Count, 1).End(xlUp).Row) ' avec la plage a2 jusqu'a la derniereligne rempli _
du sheets "employes"
Set c = .Find(T_nom, LookIn:=xlValues) 'on va tester si le nom qui est dans le "T_NOM" existe
If Not c Is Nothing Then 'si il existe
Sheets("employes").Rows(.Find(T_nom, LookIn:=xlValues).Row).Delete 'la ligne comportant ce nom sera supprimer
Else
' si il existe pas le message box te le signalant
MsgBox "ce nom n'existe pas" & vbCrLf & "entrez un nom a nouveau"
End If
End With
End If
'ici on vide les textboxs pour eviter de reloader le userform comme tu le fesait avant
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then ctrl.Value = ""
Next
End Sub
Private Sub F_employes_Click()
End Sub
Private Sub SpinButton2_Change()
Dim i As Long
i = Me.SpinButton2.Value
With Feuil2
nomrecherche = .Cells(i, 1)
ligne = i
T_nom = .Cells(i, 1)
T_prenom = .Cells(i, 2)
T_fonction = .Cells(i, 3)
T_matricule = .Cells(i, 4)
T_datedenaissance = .Cells(i, 5)
T_adresse = .Cells(i, 6)
T_codepostal = .Cells(i, 7)
T_ville = .Cells(i, 8)
T_pays = .Cells(i, 9)
T_salairebrutannuel = .Cells(i, 10)
T_numerodetelephone = .Cells(i, 11)
T_numerodegsm = .Cells(i, 12)
T_email = .Cells(i, 13)
End With
End Sub
Private Sub SpinButton2_SpinDown()
If Me.SpinButton2.Value < 2 Then Me.SpinButton2.Value = Feuil2.Range("A65536").End(xlUp).Row
End Sub
Private Sub SpinButton2_SpinUp()
If Me.SpinButton2.Value > Feuil2.Range("A65536").End(xlUp).Row Then Me.SpinButton2.Value = 2
End Sub
Private Sub T_datedenaissance_Change()
Dim Valeur As Byte
T_datedenaissance.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
Valeur = Len(T_datedenaissance)
If Valeur = 2 Or Valeur = 5 Then T_datedenaissance = T_datedenaissance & "/"
End Sub
Private Sub T_numerodetelephone_Change()
End Sub |