Listbox affiche selon condition
Bonjour,
Pour le moment j'ai une listbox qui m'affiche des infos venant de ma base de donnée :
If Me.OptionButton3.Value = True Then 'Si bouton = Facture
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
Else
Qui fonctionne parfaitement.
J'aimerais par contre le modifier pour qu'il affiche uniquement les lignes (de ma feuille "Facture")
Si, et seulement si il y à un "1" dans la colonne CQ
Si vous avez une idée merci à vous
Bonjour,
a priori
For Ligne = DerLigne To 3 Step -1
With .Cells(Ligne, 1)
If .Value <> 0 Then
If InStr(LCase$(.Value), LCase$(TextBox1)) > 0 Then
If .Offset(,95).value = 1 then ' adapter 95 pour que le décalage "tombe" sur colonne CQ
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 If
End With
Next Ligne
A+
If Me.OptionButton4.Value = True Then 'Acompte en cours
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
If .Offset(, 95).Value = 1 Then ' adapter 95 pour que le décalage "tombe" sur colonne CQ
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 If
End With
Next Ligne
End With
Aucune erreur mais liste vide malgré la présence de plusieurs "1" en CQ (qui est bien 95)...
Voici le code complet
C'est la dernière partie que j'essaie de faire fonctionner
pour que quand "OptionButton4.Value = True" alors il affiche si dans CQ = 1
Private Sub TextBox1_Change()
If Me.OptionButton1.Value = True Then 'Clients
Dim DerLigne&, Ligne&
ListBox1.Clear
With Worksheets("Clients")
DerLigne = .Cells(Rows.Count, 2).End(xlUp).Row
For Ligne = DerLigne To 4 Step -1
With .Cells(Ligne, 2)
If .Value <> 0 Then
If InStr(LCase$(.Value), LCase$(TextBox1)) > 0 Then
ListBox1.AddItem ' colonne
ListBox1.List(ListBox1.ListCount - 1, 0) = .Value 'Nom B
ListBox1.List(ListBox1.ListCount - 1, 1) = .Offset(, 1) 'Prénom C
ListBox1.List(ListBox1.ListCount - 1, 2) = .Offset(, 2) 'Société D
ListBox1.List(ListBox1.ListCount - 1, 3) = .Offset(, 3) 'Adresse E
ListBox1.List(ListBox1.ListCount - 1, 4) = .Offset(, 4) 'C.P F
ListBox1.List(ListBox1.ListCount - 1, 5) = .Offset(, 5) 'Ville G
ListBox1.List(ListBox1.ListCount - 1, 6) = .Offset(, 6) 'Tél H
ListBox1.List(ListBox1.ListCount - 1, 7) = .Offset(, 7) 'Mail I
ListBox1.List(ListBox1.ListCount - 1, 8) = .Offset(, 8) 'Num T.V.A J
End If
End If
End With
Next Ligne
End With
Else
If Me.OptionButton3.Value = True Then 'Facture
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
Else
If Me.OptionButton2.Value = True Then 'Devis
ListBox1.Clear
With Worksheets("Devis")
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
Else
If Me.OptionButton4.Value = True Then 'Acompte en cours
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
If .Offset(, 95).Value = 1 Then ' adapter 95 pour que le décalage "tombe" sur colonne CQ
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 If
End With
Next Ligne
End With
End If
End If
End If
End If
End Sub
essayer de faire afficher le contenu par
MsgBox .Offset(, 95).Value
pour voir s'il y a bien une donnée et vérifier qu'il y ait bien 1 et pas "1".
Msgbox à l'infini...
Bon, on se passera du contenu alors !!!
Bonne suite
c'est bon résolu ! merci
c'est bon résolu ! merci
Pour ceux qui ont suivi le fil et pour ceux qui rencontreraient un cas similaire, il pourrait être intéressant de savoir comment ?
avec ta réponse...
mais en effet je me suis tromper de numéro de colonne du coup il trouvais rien ...