Bonjour,
J'ai crée un petit formulaire, on choisi la section puis la classe. Après avoir choisi la section (Si 45t = 45t), alors on ajoute la classe (T3 dans mon exemple). Le problème c'est que on peut avoir 2 sections et classe identique pour un code produit différent.
Comment faire pour ne pas ajouter 2 fois une même valeur dans une listbox ? Merci.
Private Sub CommandButton1_Click()
Dim derniere_ligne As Long, i As Long
'supprime les données du formulaire bouton Reset
ListBox1.Clear
ComboBox1.Clear
ComboBox2.Clear
derniere_ligne = Cells(1, 6).End(xlDown).Row
'insère les données dans les box
For i = 2 To derniere_ligne
ComboBox1.AddItem Cells(i, 5)
ComboBox2.AddItem Cells(i, 6)
Next
End Sub
Private Sub UserForm_Initialize()
Dim derniere_ligne As Long, i As Long
derniere_ligne = Cells(1, 6).End(xlDown).Row 'ligne, colonne
'insère les données dans les combobox 1 & 2
For i = 2 To derniere_ligne
ComboBox1.AddItem Cells(i, 5)
ComboBox2.AddItem Cells(i, 6)
Next
End Sub
Private Sub ListBox1_Click()
'la réponse est affichée en B18
Range("B18") = ListBox1.Value
End Sub
Private Sub ComboBox1_Change()
Dim derniere_ligne As Long, i As Long
derniere_ligne = Cells(1, 1).End(xlDown).Row 'ligne 1, colonne 1
If ComboBox2.Value = "" Then
ListBox1.Clear
For i = 2 To derniere_ligne
If CStr(ComboBox1.Value) = CStr(Cells(i, 2).Value) Then
ListBox1.AddItem Cells(i, 1).Value
End If
Next
ComboBox2.Clear
For i = 2 To derniere_ligne
If CStr(ComboBox1.Value) = CStr(Cells(i, 2).Value) Then
ComboBox2.AddItem Cells(i, 3).Value
End If
Next
Else
ListBox1.Clear
For i = 2 To derniere_ligne
If CStr(ComboBox1.Value) = CStr(Cells(i, 2).Value) And ComboBox2.Value = Cells(i, 3).Value Then
ListBox1.AddItem Cells(i, 1).Value
End If
Next
End If
End Sub