Petit soucis pour remplir une listbox avec la cellule active

JONEY76

XLDnaute Occasionnel
Bonjour à tous,


Le fichier :

J'ai un moteur de recherche, je cherche un mot dans la classeur, le mot est trouvé est la cellule contenant ce mot est coloriée en vert, jusqu'ici tout va bien

Mon problème:

Il y a une listbox et je voudrais que la ligne contenant le mot soit affichée dans la listbox
La cellule ne sera pas forcément dans la même colonne par contre la ligne dans la liste box
commencera de la colonne A à ...

Je me plante sur le .rowsource
 

Pièces jointes

  • 1 RECHERCHE SUR UN CLASSEUR COMPLET ET COLORE LA CELLULE TROUVEE.xls
    43.5 KB · Affichages: 113
Dernière édition:

JONEY76

XLDnaute Occasionnel
Re : Petit soucis pour remplir une listbox avec la cellule active

Code:
Private Sub CommandButton1_Click()
 Dim celluletrouvee As String

'recherche le texte entré dans la textbox1
texte_a_rechercher = TextBox1.Value

'si la textbox est vide alors on sort
If texte_a_rechercher = "" Then Exit Sub

'Pour chaque feuille du classeur
For Each feuille In Worksheets
    feuille.Select
    Range("C2").Select
    
    
    With feuille.Cells
        Set C = .Find(texte_a_rechercher, LookIn:=xlValues)
        If Not C Is Nothing Then
            firstAddress = C.Address
            Do
                C.Select
                ActiveCell.Select
                
                
                [COLOR="Red"]'remplir la listbox avec la valeur ligne
                'de la cellule trouvée
                celluletrouvee = ActiveCell.Address
                
                With ListBox1
                .RowSource = celluletrouvee & ":" & celluletrouvee
                .ColumnCount = 6
                
                End With[/COLOR]
                
      'Colore en vert la cellule active
    With Selection.Interior
        .ColorIndex = 4
        .Pattern = xlSolid
    End With
    
    'Message pour chercher le suivant
                rep = MsgBox("Recherche du suivant", vbOKCancel, "Recherche")
                If rep = vbCancel Then Exit Sub
                
                'supprimer la couleur de la cellule trouvée précédement
                ActiveCell.Select
    Selection.Interior.ColorIndex = xlNone
    
    With ListBox1
    .RowSource = "a1:a1"
    End With
    
    

                Set C = .FindNext(C)
                If C Is Nothing Then
                    Adresse_encours = 0
                Else
               
                    Adresse_encours = C.Address
                End If
            Loop While Not (C Is Nothing) And (Adresse_encours <> firstAddress)
        End If
    End With
Next feuille

'Message lorsque la boucle ne trouve plus de mot
MsgBox "Pas d'autre résultat,RECHERCHE TERMINEE !!"
TextBox1 = ""

 Sheets("Feuil1").Select
    Range("A2").Select
End Sub
 

kjin

XLDnaute Barbatruc
Re : Petit soucis pour remplir une listbox avec la cellule active

Bonsoir,
Code:
Private Sub CommandButton1_Click()
ListBox1.Clear
If TextBox1 = "" Then Exit Sub
For Each ws In Worksheets
    With ws
        Set c = .UsedRange.Find(TextBox1, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                dcol = .Cells(c.Row, 256).End(xlToLeft).Column
                With ListBox1
                    If dcol > .ColumnCount Then .ColumnCount = dcol
                    .ColumnWidths = 50
                    .AddItem ws.Cells(c.Row, 1)
                    x = ListBox1.ListCount - 1
                    For i = 2 To dcol
                        ListBox1.List(x, i - 1) = ws.Cells(c.Row, i)
                    Next
                End With
                Set c = .UsedRange.FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
Next

End Sub

Edit : Je ne comprends pas ta signature !

A+
kjin
 
Dernière édition:

Discussions similaires

Réponses
18
Affichages
621

Statistiques des forums

Discussions
312 196
Messages
2 086 102
Membres
103 117
dernier inscrit
augustin.morille