je suis entrain de créer un formulaire afin de filtré sur deux listes déroulantes;
si par exemple on a plusieurs ID, pour chaque ID y a plusieurs codes articles, je cherche à trouver un code article d'un ID, pour effectuer des modifs à des textboxes...

je n'ai malheureusement pas réussi à résoudre le problème. j'ai créée le bouton rechercher mais quand j'entre un ID et article le moteur me montre les données d'un autre ...


Voici mon code

Code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub CommandButton1_Click()
'doucle click bouton ajouter
If ComboBox1.Value = "" Then
    MsgBox "Veuillez renseigner le champs   'ID BL"
Else
    Dim ligne As Integer
    If MsgBox("confirmez-vous l'ajout des données?", vbYesNo, "confirmation") = vbYes Then
    Worksheets("Feuil1").Select
    ligne = Sheets("Feuil1").Range("A456541").End(xlUp).Row + 1
    Cells(ligne, 1) = ComboBox1.Value
    Cells(ligne, 2) = ComboBox2.Value
    Cells(ligne, 3) = TextBox1.Value
    Cells(ligne, 4) = TextBox2.Value
    Cells(ligne, 5) = TextBox3.Value
    Cells(ligne, 6) = TextBox4.Value
    Cells(ligne, 7) = TextBox5.Value
    Cells(ligne, 8) = TextBox6.Value
    Cells(ligne, 9) = TextBox7.Value
    Cells(ligne, 10) = TextBox8.Value
 
    Unload UserForm1
    UserForm1.Show
    Else
    End If
   End If
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub CommandButton2_Click()
'doucle click bouton rechercher
 Dim no_ligne As Integer
 
If Not ComboBox1.Value = "" Then
 
Sheets("Feuil1").Select
For i = 2 To NbLignes
    If ComboBox1.Value = Cells(i, 1) And ComboBox2.Value = Cells(i, 2) Then
    no_ligne = i
    Exit For
    End If
Next i
 
 
    no_ligne = ComboBox1.ListIndex + 2
    ComboBox1.Value = Cells(no_ligne, 1).Value
    ComboBox2.Value = Cells(no_ligne, 2).Value
    TextBox1.Value = Cells(no_ligne, 3).Value
    TextBox2.Value = Cells(no_ligne, 4).Value
    TextBox3.Value = Cells(no_ligne, 5).Value
    TextBox4.Value = Cells(no_ligne, 6).Value
    TextBox5.Value = Cells(no_ligne, 7).Value
    TextBox6.Value = Cells(no_ligne, 8).Value
    TextBox7.Value = Cells(no_ligne, 9).Value
    TextBox8.Value = Cells(no_ligne, 10).Value
Else
End If
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub CommandButton3_Click()
'doucle click bouton modifier
Dim modif As Integer
 
 
If Not ComboBox1.Value = "" Then
 
Sheets("Feuil1").Select
 
For i = 2 To NbLignes
    If ComboBox1.Value = Cells(i, 1) And ComboBox2.Value = Cells(i, 2) Then
    modif = i
    Exit For
    End If
Next i
 
    Cells(modif, 1) = ComboBox1.Value
    Cells(modif, 2) = ComboBox2.Value
    Cells(modif, 3) = TextBox1.Value
    Cells(modif, 4) = TextBox2.Value
    Cells(modif, 5) = TextBox3.Value
    Cells(modif, 6) = TextBox4.Value
    Cells(modif, 7) = TextBox5.Value
    Cells(modif, 8) = TextBox6.Value
    Cells(modif, 9) = TextBox7.Value
    Cells(modif, 10) = TextBox8.Value
 
    MsgBox ("Modification effectuer")
    Else
    MsgBox ("Veuillez sélectionné le Nom/Prénom de la personne a modifier")
    Exit Sub
    End If
    Unload UserForm1
    UserForm1.Show 0
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
Private Sub CommandButton4_Click()
Unload UserForm1
End Sub
 
Private Sub CommandButton5_Click()
'for addition
TextBox7.Value = Val(TextBox7.Value) - Val(TextBox6.Value)
 
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Private Sub UserForm_Initialize()
    'Définit la feuille contenant les données
    Set Ws = Worksheets("Feuil1")
    'Définit le nombre de lignes dans la colonne A
    NbLignes = Ws.Range("A65536").End(xlUp).Row
 
    'Remplissage du ComboBox1
    Alim_Combo 1
 
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
Private Sub ComboBox1_Change()
    'Remplissage Combo2
    Alim_Combo 2, ComboBox1.Value
End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
'Procédure pour alimenter les ComboBox
Private Sub Alim_Combo(CbxIndex As Integer, Optional Cible As Variant)
    Dim j As Integer
    Dim Obj As MSForms.ComboBox
 
    'Définit le ComboBox à remplir
    Set Obj = Me.Controls("ComboBox" & CbxIndex)
    'Supprime les anciennes données
    Obj.Clear
 
    'alimente le Combobox initial (Combobox1)
    If CbxIndex = 1 Then
        'Boucle sur les lignes de la colonne A (à partir de la 2eme ligne)
        For j = 2 To NbLignes
            Obj = Ws.Range("A" & j)
            'Remplit le ComboBox sans doublons
            If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j)
        Next j
    Else
        'Alimentation conditionnelle des autres Combobox en fonction de
        'ce qui est sélectionnée dans le contrôle précédent:
        '(La sélection du ComboBox1 définit le contenu du ComboBox2,
        'La sélection du ComboBox2 définit le contenu du ComboBox3 …etc...)
        For j = 2 To NbLignes
            If Ws.Range("A" & j).Offset(0, CbxIndex - 2) = Cible Then
                Obj = Ws.Range("A" & j).Offset(0, CbxIndex - 1)
                If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j).Offset(0, CbxIndex - 1)
            End If
        Next j
   End If
 
   'Enlève la sélection dans le ComboBox
   Obj.ListIndex = -1
End Sub
Pièce jointe 499586