XL 2019 Aide sur une recherche listbox

dgeo27

XLDnaute Junior
Bonjour,

J'ai un code en vba (usf) qui m'affiche des données de mes factures clients.
Dans la feuille excel "facture" en :
colonne 1 = n° facture
colonne 2 = nom
colonne 3 = prénom
ect..

Pour le moment la recherche grâce à la barre fonctionne mais uniquement si je recherche un numéro de facture (qui sont trier déjà dans l'odre)
donc cela me sert presque à rien... J'aimerais modifier le code sans devoir tout recoder car mon programme fonctionne et est très gros.

Ce que j'aimerais :
C'est de modifier la recherche par le NOM et non pas par le n° de la facture ou alors en MULTI recherche pourquoi pas...

Lorsque j'essaie et que je modifie la ligne : With .Cells(Ligne, 1) par : With .Cells(Ligne, 2)
Oui sa fonctionne donc sa recherche par nom mais sa supprime complétement les n° de facture de ma listbox

Voici le code :

VB:
  If Me.OptionButton3.Value = True Then 'FactureTextBox1
 
  ListBox1.Clear
  With Worksheets("Facture")
    DerLigne = .Cells(Rows.Count, 2).End(xlUp).Row
    For Ligne = DerLigne To 3 Step -1
      With .Cells(Ligne, 1)
        If .Value <> 0 Then
          If InStr(LCase$(.Value), LCase$(TextBox1)) > 0 Then
            ListBox1.AddItem
            ListBox1.List(ListBox1.ListCount - 1, 0) = .Value
            ListBox1.List(ListBox1.ListCount - 1, 1) = .Offset(, 1)
            ListBox1.List(ListBox1.ListCount - 1, 2) = .Offset(, 3)
            ListBox1.List(ListBox1.ListCount - 1, 3) = .Offset(, 4)
            ListBox1.List(ListBox1.ListCount - 1, 4) = .Offset(, 5)
            ListBox1.List(ListBox1.ListCount - 1, 5) = .Offset(, 6)
            ListBox1.List(ListBox1.ListCount - 1, 6) = .Offset(, 7)
            ListBox1.List(ListBox1.ListCount - 1, 7) = .Offset(, 8)
          End If
        End If
      End With
    Next Ligne
  End With

Merci
 

patricktoulon

XLDnaute Barbatruc
re

bonjour
si tu reflechi 2 secondes ;)
cela dit il y a des moyen de faire moins verbeux et plus simple
mais bon voila ta methode basée sur la colonne 2 si c'est bien la colonne des noms
If Me.OptionButton3.Value = True Then 'FactureTextBox1

ListBox1.Clear
With Worksheets("Facture")
DerLigne = .Cells(Rows.Count, 2).End(xlUp).Row
For Ligne = DerLigne To 3 Step -1
With .Cells(Ligne, 2)
If .Value <> 0 Then
If InStr(LCase$(.Value), LCase$(TextBox1)) > 0 Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Offset(,- 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = .Value
ListBox1.List(ListBox1.ListCount - 1, 2) = .Offset(, 1)
ListBox1.List(ListBox1.ListCount - 1, 3) = .Offset(, 3)
ListBox1.List(ListBox1.ListCount - 1, 4) = .Offset(, 4)
ListBox1.List(ListBox1.ListCount - 1, 5) = .Offset(, 5)
ListBox1.List(ListBox1.ListCount - 1, 6) = .Offset(, 6)
ListBox1.List(ListBox1.ListCount - 1, 7) = .Offset(, 7)
ListBox1.List(ListBox1.ListCount - 1, 8) = .Offset(, 8)
End If
End If
End With
Next Ligne
End With
 

dgeo27

XLDnaute Junior
re

bonjour
si tu reflechi 2 secondes ;)
cela dit il y a des moyen de faire moins verbeux et plus simple
mais bon voila ta methode basée sur la colonne 2 si c'est bien la colonne des noms
If Me.OptionButton3.Value = True Then 'FactureTextBox1

ListBox1.Clear
With Worksheets("Facture")
DerLigne = .Cells(Rows.Count, 2).End(xlUp).Row
For Ligne = DerLigne To 3 Step -1
With .Cells(Ligne, 2)
If .Value <> 0 Then
If InStr(LCase$(.Value), LCase$(TextBox1)) > 0 Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Offset(,- 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = .Value
ListBox1.List(ListBox1.ListCount - 1, 2) = .Offset(, 1)
ListBox1.List(ListBox1.ListCount - 1, 3) = .Offset(, 3)
ListBox1.List(ListBox1.ListCount - 1, 4) = .Offset(, 4)
ListBox1.List(ListBox1.ListCount - 1, 5) = .Offset(, 5)
ListBox1.List(ListBox1.ListCount - 1, 6) = .Offset(, 6)
ListBox1.List(ListBox1.ListCount - 1, 7) = .Offset(, 7)
ListBox1.List(ListBox1.ListCount - 1, 8) = .Offset(, 8)
End If
End If
End With
Next Ligne
End With
Oufff un GRAND merci

Franchement non j'ai rien compris au code et encore moins à ta réponse mais elle fonctionne :D
 

Discussions similaires

Réponses
4
Affichages
191
Réponses
17
Affichages
803

Membres actuellement en ligne

Statistiques des forums

Discussions
312 084
Messages
2 085 194
Membres
102 810
dernier inscrit
mohammedaminelahbali