XL 2016 alimenter Combobox a partir d'un résultat d'une listbox

bandimalou

XLDnaute Occasionnel
bonjour a tous et bonnes vacances au juillettiste!!!!!

j'ai fait un formulaire pour mes demandes d'interventions qui fonctionne très bien, je souhaiterais l’améliorer mais je bloque alors je sollicite votre aide.

sur le formulaire il y a un champ de recherche qui affiche le résultat dans une listbox,
mais je souhaiterais pouvoir filtrer ce résultat avec le combobox emplacement (en jaune sur le formulaire) avec la 4eme colonne de la listbox.

merci de votre aide

Cyril
 

Pièces jointes

  • FICHIER CLIENT v1 - Copie.xlsm
    598.6 KB · Affichages: 18

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
VB:
Private Sub TextBoxRech_Change()
  If Me.TextBoxRech <> "" Then
     mots = Split(Trim(Me.TextBoxRech), " ")
     Tbl = choix
     For i = LBound(mots) To UBound(mots)
        Tbl = Filter(Tbl, mots(i), True, vbTextCompare)
     Next i
     If UBound(Tbl) > -1 Then
        Dim b(): ReDim b(1 To UBound(Tbl) + 1, 1 To NbCol + 1)
        For i = LBound(Tbl) To UBound(Tbl)
          a = Split(Tbl(i), "|")
          j = a(NcolInt)
          For c = 1 To NbCol: b(i + 1, c) = BD(j, c): Next c
          b(i + 1, c) = j
        Next i
        Me.ListBox1.List = b
       '--- combobox
       TblListBox = Me.ListBox1.List
       Set d = CreateObject("scripting.dictionary")
       For j = 1 To UBound(TblListBox)
         d(TblListBox(j, 3)) = ""
       Next j
       Me.ComboBox1.List = d.keys
     Else
       Me.ListBox1.Clear
     End If
  Else
     UserForm_Initialize
  End If
End Sub

Code:
Private Sub ComboBox1_click()
  If Me.ComboBox1 <> "" Then
    clé = Me.ComboBox1: n = 0
    Dim Tbl()
    TblListBox = Me.ListBox1.List
    For i = LBound(TblListBox) To UBound(TblListBox)
     If TblListBox(i, 3) Like clé Then
        n = n + 1: ReDim Preserve Tbl(LBound(TblListBox, 2) To UBound(TblListBox, 2), 1 To n)
        For k = LBound(TblListBox) To UBound(TblListBox, 2): Tbl(k, n) = TblListBox(i, k): Next k
     End If
    Next i
    If n > 0 Then Me.ListBox1.Column = Tbl: Me.ComboBox1.List = Array(clé) Else Me.ListBox1.Clear
   End If
End Sub


Boisgontier
 

Pièces jointes

  • Copie de FormRechercheModifAjoutSupCombobox-3.xls
    237.5 KB · Affichages: 17

bandimalou

XLDnaute Occasionnel
merci beaucoup,c'est vraiment super.
une petite question, j'ai rempli ton tableau avec ma base mais lorsque je teste, le combobox me propose toujours un choix de moins qu'il n'y a de reponse dans la listbox.
si tu as une idee
merci beaucoup encore
Cyril
 

Discussions similaires

Statistiques des forums

Discussions
312 176
Messages
2 085 959
Membres
103 064
dernier inscrit
litteuld