precision de recherche!!!

HabiboU

XLDnaute Nouveau
salut
voila j'ai un tableau excel avec 50 colonne et 23232 ligne je souhaite préciser la recherche avec usf dans 3 colonne seulement mais les resulta ce fera dans une listbox avec la ligne entière . ce que j'ai réussi a faire jusqu’à présent c étendre la recherche sur toute les colonne ce qui donne un resulta tres :confused: .


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
NbreCol = 50 '<---- Nombre de colonnes à prendre en compte
With Sheets("ANOMAL").Activate
Dim Sht As Worksheet
Set Sht = Worksheets(ANOMAL)
If TextBox1 = "" Then
ListBox1.Clear
Else
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)

S = "*" & LCase(TextBox1) & "*"
For i = 1 To Lmax - 1
For m = 1 To NbreCol
LigneOK(i) = False
If LCase(V(i, m)) Like S Then
LigneOK(i) = True
Nbr = Nbr + 1
Exit For
End If
Next m
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
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 With
 

Pièces jointes

  • code.docx
    13.2 KB · Affichages: 49

HabiboU

XLDnaute Nouveau
Re : precision de recherche!!!

salut BrunoM45
oui bien sur et merci pour votre réponse . voici un exemple fichier excel avec un USF
 

Pièces jointes

  • Classeur2.xlsm
    27.4 KB · Affichages: 57
  • Classeur2.xlsm
    27.4 KB · Affichages: 53
  • Classeur2.xlsm
    27.4 KB · Affichages: 50
C

Compte Supprimé 979

Guest
Re : precision de recherche!!!

Bonsoir,

Ne pas confondre une variable définit
Code:
Feuil1 = "NomFeuille"
Set Sht = Worksheets(Feuil1)

avec un nom de feuille
Code:
Set Sht = Worksheets("Feuil1")

Voici ton code corrigé
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
  Dim Sht As Worksheet


  NbreCol = 50     '<---- Nombre de colonnes à prendre en compte


  Set Sht = Worksheets("Feuil1")
  If TextBox1 = "" Then
    ListBox1.Clear
  Else
    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)


    '-------------------------------------------------------------------------------------'
    ' 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
        LigneOK(i) = False
        If LCase(V(i, m)) Like S Then
          LigneOK(i) = True
          Nbr = Nbr + 1
          Exit For
        End If
      Next m
    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
        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

A+
 

HabiboU

XLDnaute Nouveau
Re : precision de recherche!!!

salut BrunoM45
merci beaucoup pour ton aide mais ça ne résous pas mon problème , je veut limité la recherche a uniquement 3 colonne L,M,N mais le résulta doit afficher toute la ligne !!!!
parce que la sa me donne un résulta pas très claire !! désoler de ta voire embêté !
j'ai c code je l'ai adapté a ma feuil le seul problème c'est qu'il n'affiche pas toute la ligne après la recherche
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
 
Dernière édition:
C

Compte Supprimé 979

Guest
Re : precision de recherche!!!

Salut HabiboU

Désolé, je pense qu'il suffit de changer
Code:
For m = 12 To NbreCol
par
Code:
For m = 12 To 14
12 à 14 étant les colonne L à N

A+
 
Dernière modification par un modérateur:

HabiboU

XLDnaute Nouveau
Re : precision de recherche!!!

juste un dernière chose comment afficher la première ligne étant donner que c'est l’entête dans listbox j'ai essayer :

Me.ListBox1.RowSource = "A2:AW23232"

mais le résulta de la recherche sera perturbé
 
C

Compte Supprimé 979

Guest
Re : precision de recherche!!!

Bonjour HabiboU

Malheureusement, ce ne sera pas possible, tu peux définir une ligne d'entête
Code:
Private Sub UserForm_Initialize()  Dim DLig As Long
  DLig = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row
  'Remarque:
  'ColumnHeads = True spécifie que la première cellule précédent
  'la plage source est utilisée comme titre dans la ListBox.
  'ColumnHeads ne fonctionne pas pour la propriété List() et la méthode AddItem.
  With Me.ListBox1
    .ColumnHeads = True
    .RowSource = "Feuil1!A3:O" & DLig
  End With
End Sub

Mais ensuite ton code de remplissage ne pourra plus fonctionner
Puisqu'avant remplissage tu efface ta Listbox
Code:
ListBox1.Clear
Et cette instruction fonctionne que si tu n'as pas définit de RowSource

A+
 

Discussions similaires

Réponses
4
Affichages
233
Réponses
2
Affichages
132
Réponses
11
Affichages
347

Statistiques des forums

Discussions
312 486
Messages
2 088 820
Membres
103 971
dernier inscrit
abdazee