Bonjour,

Mes données sont classées dans un tableau de 11 colonnes, de la manière suivante :

A => Année ; B => Mois ; C => BC ; D => DA ; E => Fournisseurs ;
F => PU ; G => Qté ; H => Montant ; I => Devis (Etat) ; J => Type ;
K=> Article

Je souhaiterais avoir ce qui suit:

Sélection de "OptionButton3" => Recherche par BC => OK
Sélection de "OptionButton4" => Recherche par Fournisseur => OK
Sélection de "OptionButton7" => Recherche par DA => Non OK
(Je voudrais ajouter ce 3eme critère pour ma recherche)

J'ai ajouté aussi à mon formulaire 3 ComboBox (pour Choisir une Année, Une Période ou un Type de produit), de manière à avoir le résultat de ma recherche selon l'Année, la Période et le Type de produit. Si vous pouvez me donner une idée de comment procéder, cela m'aidera aussi bien.
En rouge ce sont ceux que je n'ai pas pu faire.

Et voici ma proposition pour l'instant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private Sub ComboBox1_Change()
  Me.ListBox1.Clear
  For Each cel In pl
    If CStr(cel.Value) = CStr(Me.ComboBox1.Value) Then
      nl = cel.Row
      With Me.ListBox1
        .AddItem Sheets("Enregistrement").Cells(cel.Row, 3)
        .List(.ListCount - 1, 1) = Sheets("Enregistrement").Cells(nl, 5)
        .List(.ListCount - 1, 9) = nl
      End With
    End If
  Next cel
  If Me.ListBox1.ListCount = 1 Then Me.ListBox1.ListIndex = 0
End Sub
'A l'Affichage dans le "ListBox1", nous aurons 3 colonnes:
1-Reférence; 2-Fournisseur; 3-Devis(Avis)

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
36
37
38
39
40
41
42
43
44
Private Sub listbox1_Click()
  nl = Me.ListBox1.Column(9, Me.ListBox1.ListIndex)
  For X = 0 To 10
    Me.Controls("TextBox" & X + 1).Value = Sheets("Enregistrement").Cells(nl, 1 + X)
  Next X
 
  With Me.TextBox1
   ' .SetFocus
    .SelStart = 0
    .SelLength = Len(.Value)
  End With
End Sub
 
Private Sub obG2()
Dim col As Variant
Dim dico As Object
Dim tbl As Variant
Dim I As Variant
Dim j As Variant
Dim temp As Variant
 
UserForm1.ComboBox1.Clear
col = IIf(UserForm1.OptionButton3.Value = True, 3, 5)
With Sheets("Enregistrement")
    Set pl = .Range(.Cells(3, col), .Cells(Application.Rows.Count, col).End(xlUp)) 'définit la plage pl
End With
 
Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
    dico(cel.Value) = ""
Next cel
tbl = dico.keys
 
For I = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
        If tbl(I) < tbl(j) Then
            temp = tbl(I)
            tbl(I) = tbl(j)
            tbl(j) = temp
        End If
    Next j
Next I
UserForm1.ComboBox1.List = tbl
End Sub
Cordialement