recherche dans une Colonne

HabiboU

XLDnaute Nouveau
salut
voila j'ai une question ! :confused: comment faire pour recherché un nombre das une colonne et le résulta sera d'afficher tous les cellule adjacent a ce nombre qui sera afficher dans une listbox ?
voila ce que j'ai pu faire mais ce e fonctionne pas !!! je crois qu'il me faut beaucoup de travaille encore pour apprendre bien le vba ?
 

Pièces jointes

  • Rch.xls
    46.5 KB · Affichages: 51

Bebere

XLDnaute Barbatruc
Re : recherche dans une Colonne

bonjour Habibou
il faut un début à tout.En comparant tu trouveras ce qui est changé
Code:
Private Sub TextBox1_Change()
Dim S As String, i As Long, Lmax As Long, Nbr As Long, k As Long, NbreCol As Long
Dim L, V, LigneOK, m As Long            '<<< ligne modifiée
NbreCol = 2     '<---- Nombre de colonnes à prendre en compte
Dim Sht As Worksheet
Set Sht = Worksheets("Feuil1")

If TextBox1 <> "" Then
    ListBox1.Clear
    Lmax = Sht.Range("A" & Sht.Rows.Count).End(xlUp).Row
    V = Range(Sht.Range("A2"), Sht.Cells(Lmax, NbreCol)).Value
    ReDim LigneOK(1 To Lmax - 1)            '<<< ligne modifiée
    
    '-------------------------------------------------------------------------------------'
    ' si on ne veut qu'une présence du texte saisi en début de cellule, conserver l'instruction suiv.
    'S = LCase(TextBox1) & "*"
    ' si le texte saisi peut se trouver n'importe où dans les cellules, conserver l'instructiion suiv.
    S = S = "*" & LCase(TextBox1) & "*"
    '-------------------------------------------------------------------------------------'
    S = "*" & LCase(TextBox1) & "*"
    For i = 1 To Lmax - 1
        For m = 1 To NbreCol                        '<<< ligne modifiée
            LigneOK(i) = False                          '<<< ligne modifiée
            If LCase(V(i, m)) Like S Then           '<<< ligne modifiée
                LigneOK(i) = True                       '<<< ligne modifiée
                Nbr = Nbr + 1                             '<<< ligne modifiée
                Exit For                                        '<<< ligne modifiée
            End If                                               '<<< ligne modifiée
        Next m                                                 '<<< ligne modifiée
    Next i
    If Nbr = 0 Then Exit Sub
        ReDim L(0 To Nbr - 1, 0 To NbreCol - 1)
        Nbr = -1
        For i = 1 To Lmax - 1
            If LigneOK(i) Then                            '<<< ligne modifiée
                Nbr = Nbr + 1
                For k = 0 To NbreCol - 1
                    L(Nbr, k) = V(i, k + 1)
                Next k
            End If
        Next i
        ListBox1.List = L
End If
ListBox1.ListIndex = -1
End Sub

'recherche avec find ( vient de l'aide).juste changer la ligne après do
Code:
Private Sub TextBox1_Change()
Dim c As Range, firstAddress As String

If TextBox1 <> "" Then
ListBox1.Clear
With Worksheets("Feuil1").Range("a1:a500")
    Set c = .Find(TextBox1, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
           ListBox1.AddItem c.Value
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With

End If
End Sub
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 508
Messages
2 089 143
Membres
104 048
dernier inscrit
Noni