Listbox n'affiche rien

Bonjour a tous

j'ai voulai afficher sur un liste box un restultat de recherche mais rien ne s'affiche! pouvez vous m'aider SVP

voici le code :

Private Sub CommandButton1_Click()

Dim critere

Dim Derniereligne As Integer, X As Integer

critere = TextBox1

If Worksheets("Recap").Cells(Rows.Count, 1).End(xlUp).Row = 1 Then

Derniereligne = 2

Else

Derniereligne = Worksheets("Recap").Cells(Rows.Count, 1).End(xlUp).Row

End If

ListBox1.Clear

For X = 1 To Derniereligne

If Feuil1.Cells(X, 3) = critere Then

Me.ListBox1.AddItem Feuil1.Cells(X, 1)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Worksheets("Recap").Cells(X, 2)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = Worksheets("Recap").Cells(X, 3)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Worksheets("Recap").Cells(X, 4)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = Worksheets("Recap").Cells(X, 5)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = Worksheets("Recap").Cells(X, 6)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = Worksheets("Recap").Cells(X, 7)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = Worksheets("Recap").Cells(X, 8)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = Worksheets("Recap").Cells(X, 9)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = Worksheets("Recap").Cells(X, 10)

End If

Next X

End Sub

j'ai corrigé ça mais toujours rien

Private Sub CommandButton1_Click()

Dim critere

Dim Derniereligne As Integer, X As Integer

critere = TextBox1

If Sheets("Recap").Cells(Rows.Count, 1).End(xlUp).Row = 1 Then

Derniereligne = 2

Else

Derniereligne = Sheets("Recap").Cells(Rows.Count, 1).End(xlUp).Row

End If

ListBox1.Clear

For X = 1 To Derniereligne

If Sheets("recap").Cells(X, 3) = critere Then

Me.ListBox1.AddItem Feuil1.Cells(X, 1)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = Sheets("Recap").Cells(X, 2)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = Sheets("Recap").Cells(X, 3)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = Sheets("Recap").Cells(X, 4)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = Sheets("Recap").Cells(X, 5)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = Sheets("Recap").Cells(X, 6)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = Sheets("Recap").Cells(X, 7)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = Sheets("Recap").Cells(X, 8)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = Sheets("Recap").Cells(X, 9)

Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = Sheets("Recap").Cells(X, 10)

End If

Next X

End Sub

Bonjour

avec un fichier on voie mieux

A+

Maurice

ok merci

voici copie exemple de mon fichier

mon problème se voie sur : Feuille "Facture"----bouton " liste facture/imprimer"---bouton "filtre"

merci

9facture.xlsm (94.77 Ko)

Bonjour,

Avec un objet tableau, il est préférable d'utiliser la classe associée. Ci-dessous code :

Private Sub CommandButton1_Click()
    Dim critere As String
    Dim X As Integer, Y As Integer

    critere = TextBox1
    Me.ListBox1.Clear
    Me.ListBox1.ColumnCount = 11

    With Feuil5.ListObjects(1)
        For X = 1 To .ListRows.Count
            If .ListColumns("Clients").DataBodyRange.Rows(X) = critere Then
                Me.ListBox1.AddItem .ListColumns("Date").DataBodyRange.Rows(X)
                For Y = 2 To Me.ListBox1.ColumnCount - 1
                    Me.ListBox1.List(Me.ListBox1.ListCount - 1, Y - 1) = .ListColumns(Y).DataBodyRange.Rows(X)
                Next Y
            End If
        Next X
    End With
End Sub

Bonjour

a voir la modife de userform Recherche

A+

Maurice

25facture.xlsm (86.88 Ko)

merci Maurice

je ne sais pas pourquoi sur le fichier que tu m'as envoyer tous marche, mais quand je copie le macro sur mon classeur le filtre montre seulement la column "DATE"!!

merci de m'aider

Bonjour

Voir le codename & ColumnCount

A+

Maurice

Private Sub UserForm_Activate()
Set Sh = Feuil5 ' = codename de Recap
    Call InitList(1, "")
End Sub

Sub InitList(Col, MaVar)
Derniereligne = Sh.Cells(Rows.Count, 1).End(xlUp).Row
    With ListBox1
        .Clear
        .ColumnCount = 11 ' a mettre
            For X = 2 To Derniereligne
                If UCase(Sh.Cells(X, Col)) Like UCase(MaVar) & "*" Then
                    .AddItem Sh.Cells(X, 1)
                        For C = 1 To 9
                          .List(.ListCount - 1, C) = Sh.Cells(X, C + 1).Text
                        Next C
                End If
            Next X
    End With
End Sub

merci

Rechercher des sujets similaires à "listbox affiche rien"