Public Nouveau As Boolean, Lig As Long, NewRef As Boolean
Private Sub ComboBox1_Change()
If NewRef = False Then
If Me.ComboBox1.MatchFound = True Then
Me.TextBox1.Value = Cells(Me.ComboBox1.ListIndex + 3, 6)
Me.TextBox2.Value = Cells(Me.ComboBox1.ListIndex + 3, 3)
Me.ComboBox2.Value = Cells(Me.ComboBox1.ListIndex + 3, 1)
Else
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.ComboBox2.Value = ""
End If
End If
NewRef = False
End Sub
Private Sub ComboBox2_Change()
NewRef = True
Lig = Columns(1).Find(Me.ComboBox2).Row
Me.TextBox1.Value = Cells(Lig, 6)
Me.TextBox2.Value = Cells(Lig, 3)
Me.ComboBox1.Value = Cells(Lig, 2)
End Sub
Private Sub CommandButton1_Click()
If Nouveau Then
Cells(Lig, 2).Value = Me.ComboBox1.Value
Cells(Lig, 6).Value = Val(Me.TextBox1)
Cells(Lig, 3).Value = Me.TextBox2
Nouveau = False
Else
Cells(Me.ComboBox1.ListIndex + 3, 6) = Val(Me.TextBox1)
End If
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Range("B3:B" & [B65000].End(xlUp).Row).Name = "mabase"
Me.ComboBox1.List = Range("mabase").Value
For Each cel In Range("A3:A" & [A65000].End(xlUp).Row)
If cel.Value <> "" Then Me.ComboBox2.AddItem (cel.Value)
Next cel
End Sub
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.ComboBox1.MatchFound = True Then
Exit Sub
Else
Nouveau = True: Lig = [B65000].End(xlUp).Row + 1
End If
End Sub