Bonjour
Le code de la macro "Private Sub CommandButton1_Click()" du module "UserForm2"
Private Sub CommandButton1_Click()
Dim c As Range
Dim firstaddress As String
Dim f1 As Worksheet, f2 As Worksheet
Application.ScreenUpdating = False
Set f1 = Sheets("Gestion des clefs")
Set f2 = Sheets("Gestion des clefs 2")
If Len(TextBox2) = 0 Then
MsgBox "saisie incomplète"
TextBox2.SetFocus: Exit Sub
End If
With f1.ListObjects("Tab_GestClefs").ListColumns(2)
Set c = .DataBodyRange.Find(Format(TextBox2.Value, "000"), LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
firstaddress = c.Address
Do
If f1.Range("B" & c.Row) = c.Value And f1.Range("E" & c.Row).Value = "" Then
f1.Unprotect PSW
f1.Range("E" & c.Row).Value = TextBox1.Value
f1.Protect PSW
Exit Do
End If
Set c = .DataBodyRange.FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
With f2.ListObjects("Tab_GestClefs4").ListColumns(2)
Set c = .DataBodyRange.Find(Format(TextBox2.Value, "000"), LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
firstaddress = c.Address
Do
If f2.Range("B" & c.Row) = c.Value And f2.Range("E" & c.Row).Value = "" Then
f2.Unprotect PSW
f2.Range("E" & c.Row).Value = TextBox1.Value
f2.Protect PSW
Exit Do
End If
Set c = .DataBodyRange.FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
Unload UserForm2
Set f1 = Nothing
Set f2 = Nothing
End Sub
Cdlt