Recherche Listbox sur plusieurs colonnes et supprimer certaines lignes

20test1.xltm (26.50 Ko)

Bonjour,

Malgré le fait qu'il existe déjà un bonne quantité de topic à ce sujet mais malheureusement je n'ai pas trouvé mon bonheur ou alors à comprendre le code afin de le modifier pour mon fichier donc j'en appelle à votre aide.

J'ai déjà réalisé un userform de recherche mais ce dernier ne marche uniquement sur la colonne référence alors que je souhaiterai sur la totalité des colonnes présentes dans le listbox sauf que je ne voit pas comment modifié le miens pour obtenir cela..

Et par ailleurs dans ma liste de pièce présente dans la feuille il y a des lignes comprenant les titres des Ensembles est ce possible de pouvoir éliminer ces lignes du listbox sans les supprimer ou alors faut il faut bricoler quelques choses pour réaliser cela ?

Cordialement

Bonjour,

Sur une copie de ton fichier ... Remplace tout le contenu du userform1 par ceci ...

Un essai ...

Option Compare Text

Private Sub Cancel_Click()
    Unload Me
End Sub

Private Sub TextBox1_Change()
Dim Lig As Long
Dim I As Long
Dim J As Long
Dim Plage As Range
Dim Cl As Range

    ListBox1.Clear

    With Worksheets("Feuil1")
        Lig = .Cells(.Rows.Count, 1).End(xlUp).Row 'sur colonne A

        Set Plage = .Range("A2:I" & Lig)
        For Each Cl In Plage
            If Cl.Value Like TextBox1.Text & "*" Then
                If Left(Cl.Value, 8) <> "Ensemble" Then
                ListBox1.AddItem .Cells(Cl.Row, 2).Value
                ListBox1.Column(1, J) = .Cells(Cl.Row, 3).Value
                ListBox1.Column(2, J) = .Cells(Cl.Row, 5).Value
                ListBox1.Column(3, J) = .Cells(Cl.Row, 6).Value
                ListBox1.Column(4, J) = .Cells(Cl.Row, 7).Value
                J = J + 1
                End If
           End If
        Next Cl
    End With
End Sub

Private Sub UserForm_Activate()
    Me.TextBox1.SetFocus
End Sub

Private Sub UserForm_Initialize()
Dim Lig As Long
Dim I As Long
Dim J As Long

    With Worksheets("Feuil1")
         Lig = .Cells(.Rows.Count, 1).End(xlUp).Row 'sur colonne A
        ListBox1.ColumnHeads = False 'ici, ne seret à rien car les entêtes ne seront pas remplies

        For I = 6 To Lig
            If Left(.Cells(I, 3).Value, 8) <> "Ensemble" Then
            ListBox1.AddItem .Cells(I, 2).Value
            ListBox1.Column(1, J) = .Cells(I, 3).Value
            ListBox1.Column(2, J) = .Cells(I, 5).Value
            ListBox1.Column(3, J) = .Cells(I, 6).Value
            ListBox1.Column(4, J) = .Cells(I, 7).Value
            J = J + 1
            End If
        Next I
    End With
End Sub

ric

Bonjour,

Merci C'est exactement ce que je recherche !

Par contre ça fonctionne parfaitement la première fois et après si on viens a supprimer pour une autre recherche ça affiche tout en x10

Merci d'avance

Bonjour,

Oupppssss!

Nouveau code ...

Private Sub TextBox1_Change()
Dim Lig As Long
Dim I As Long
Dim J As Long
Dim Plage As Range
Dim Cl As Range

    ListBox1.Clear

    If Me.TextBox1 = "" Then
        Call ChargeLaListbox
        Exit Sub
    End If

    With Worksheets("Feuil1")
        Lig = .Cells(.Rows.Count, 1).End(xlUp).Row 'sur colonne A

        Set Plage = .Range("A2:I" & Lig)
        For Each Cl In Plage
            If Cl.Value Like TextBox1.Text & "*" Then
                If Left(Cl.Value, 8) <> "Ensemble" Then
                ListBox1.AddItem .Cells(Cl.Row, 2).Value
                ListBox1.Column(1, J) = .Cells(Cl.Row, 3).Value
                ListBox1.Column(2, J) = .Cells(Cl.Row, 5).Value
                ListBox1.Column(3, J) = .Cells(Cl.Row, 6).Value
                ListBox1.Column(4, J) = .Cells(Cl.Row, 7).Value
                J = J + 1
                End If
           End If
        Next Cl
    End With
End Sub

Private Sub UserForm_Activate()
    Me.TextBox1.SetFocus
End Sub

Private Sub UserForm_Initialize()
   Call ChargeLaListbox
End Sub

Sub ChargeLaListbox()
Dim Lig As Long
Dim I As Long
Dim J As Long

    With Worksheets("Feuil1")
         Lig = .Cells(.Rows.Count, 1).End(xlUp).Row 'sur colonne A
        ListBox1.ColumnHeads = False 'ici, ne seret à rien car les entêtes ne seront pas remplies

        For I = 6 To Lig
            If Left(.Cells(I, 3).Value, 8) <> "Ensemble" Then
            ListBox1.AddItem .Cells(I, 2).Value
            ListBox1.Column(1, J) = .Cells(I, 3).Value
            ListBox1.Column(2, J) = .Cells(I, 5).Value
            ListBox1.Column(3, J) = .Cells(I, 6).Value
            ListBox1.Column(4, J) = .Cells(I, 7).Value
            J = J + 1
            End If
        Next I
    End With
End Sub

ric

Merci ça marche parfaitement maintenant !

Rechercher des sujets similaires à "recherche listbox colonnes supprimer certaines lignes"