Emplir listview selon 2 conditions

Résolu
cs_lanetmel Messages postés 6 Date d'inscription lundi 2 avril 2012 Statut Membre Dernière intervention 8 mai 2012 - 7 mai 2012 à 02:36
cs_lanetmel Messages postés 6 Date d'inscription lundi 2 avril 2012 Statut Membre Dernière intervention 8 mai 2012 - 8 mai 2012 à 18:01
Bonjour à tous,

On m'a déjà beaucoup aidé et je vous remercie de tout coeur..Mais là ça fais des heures que je cherche et je comprends pas pourquoi ça fait ça. :
Je veux emplir ma listview Selon 2 critères : Avec un seul ça fonctionnais très bien (x et Textbox3) mais là je me suis rendu compte que je ne dois afficher la ligne dans ma listview seulement si x = Textbox3 ET (là c'est moi qui a ajouté y ) si en plus dans la colonne 4 de ma feuille de données (infos) c'est écrit entrée (comme indiqué par ma Textbox54)
Mais depuis que j'ai ajouté ma 2ème condition, ça affiche tout en triple et ça met quand même les lignes qui ne répondent pas à la deuxième condition...J'ai misdevant les choses que j'ai ajouté..J'aimgine que c'est une question de formulation mais j'en ai essayé plusieurs et ça fonctionne pas..

Une idée quelqu'un?

Voici mon code :
Private Sub Textbox3_change() ' lot, emplir Listview
Dim sh As Worksheet
Dim c As Long, x As Variant
Dim y as variant

Set sh = Worksheets("infos")

With ListView1: .Gridlines True: .View 3: .FullRowSelect = True
With .ColumnHeaders
.Clear
.Add , , sh.Cells(3, 1).Value, 50
.Add , , sh.Cells(3, 2).Value, 40
.Add , , sh.Cells(3, 6).Value, 60
.Add , , sh.Cells(3, 5).Value, 30
.Add , , sh.Cells(3, 4).Value, 70
.Add , , "Sel/M", 58
.Add , , "1Com", 58
.Add , , "2Com", 58
.Add , , "3Com", 58
.Add , , "3B", 58
.Add , , "Pal", 58
.Add , , "Autre", 58
.Add , , "Coût", 58
.Add , , "Fournisseur", 70
End With

For Each x In sh.Range("A6:A" & Cells(Rows.Count,
1).End(xlUp).Row) ' Va trouver le lot demandé dans textbox3
For Each y In sh.Range("D6:D" & Cells(Rows.Count, 1).End(xlUp).Row) ' Va trouver seulement les entrées

If x.Value TextBox3.Value And y.Value TextBox54.Value Then
With .listitems
.Add , , sh.Cells(x.Row, 1)
End With
With .listitems(.listitems.Count).ListSubItems
.Add , , sh.Cells(x.Row, 2)
.Add , , sh.Cells(x.Row, 6)
.Add , , sh.Cells(x.Row, 5)
.Add , , sh.Cells(x.Row, 4)
.Add , , sh.Cells(x.Row, 11) + sh.Cells(x.Row, 13) + sh.Cells(x.Row, 15) + sh.Cells(x.Row, 17) + sh.Cells(x.Row, 19) ' grade Sel/m
.Add , , sh.Cells(x.Row, 21) + sh.Cells(x.Row, 23) + sh.Cells(x.Row, 25) + sh.Cells(x.Row, 27) + sh.Cells(x.Row, 29) ' grade 1com
.Add , , sh.Cells(x.Row, 31) + sh.Cells(x.Row, 33) + sh.Cells(x.Row, 35) ' grade 2 com
.Add , , sh.Cells(x.Row, 37) + sh.Cells(x.Row, 41) ' grade 3 com
.Add , , sh.Cells(x.Row, 43) ' grade 3B com
.Add , , sh.Cells(x.Row, 45) ' grade pal
.Add , , sh.Cells(x.Row, 47) + sh.Cells(x.Row, 49) + sh.Cells(x.Row, 51) + sh.Cells(x.Row, 53) + sh.Cells(x.Row, 55) + sh.Cells(x.Row, 57) ' grade autre
.Add , , sh.Cells(x.Row, 177) 'coût
.Add , , sh.Cells(x.Row, 8) 'Fournisseur
End With
End If

Next
Next
End With




ListView1.Sorted = False
ListView1.SortKey = 0
'ListView1.SortOrder = lvwAscending
ListView1.Sorted = True

TextBox5.Value = Date

End Sub

1 réponse

cs_lanetmel Messages postés 6 Date d'inscription lundi 2 avril 2012 Statut Membre Dernière intervention 8 mai 2012
8 mai 2012 à 18:01
Bonjour à tous,

Pour ceux que ça pourrait aider voici la solution :

Private Sub Textbox3_change() ' lot, emplir Listview
Dim sh As Worksheet
Dim c As Long, x As Variant


Set sh = Worksheets("infos")

With ListView1: .Gridlines True: .View 3: .FullRowSelect = True
With .ColumnHeaders
.Clear
.Add , , sh.Cells(3, 1).Value, 50
.Add , , sh.Cells(3, 2).Value, 40
.Add , , sh.Cells(3, 6).Value, 60
.Add , , sh.Cells(3, 5).Value, 30
.Add , , sh.Cells(3, 4).Value, 70
.Add , , "Sel/M", 58
.Add , , "1Com", 58
.Add , , "2Com", 58
.Add , , "3Com", 58
.Add , , "3B", 58
.Add , , "Pal", 58
.Add , , "Autre", 58
.Add , , "Coût", 58
.Add , , "Fournisseur", 70
End With

For Each x In sh.Range("A6:A" & Cells(Rows.Count,
1).End(xlUp).Row) ' Va trouver le lot demandé dans textbox3
If x.Value TextBox3.Value And Cells(x.Row, 4).Value TextBox54.Value Then


With .listitems
.Add , , sh.Cells(x.Row, 1)
End With
With .listitems(.listitems.Count).ListSubItems
.Add , , sh.Cells(x.Row, 2)
.Add , , sh.Cells(x.Row, 6)
.Add , , sh.Cells(x.Row, 5)
.Add , , sh.Cells(x.Row, 4)
.Add , , sh.Cells(x.Row, 11) + sh.Cells(x.Row, 13) + sh.Cells(x.Row, 15) + sh.Cells(x.Row, 17) + sh.Cells(x.Row, 19) ' grade Sel/m
.Add , , sh.Cells(x.Row, 21) + sh.Cells(x.Row, 23) + sh.Cells(x.Row, 25) + sh.Cells(x.Row, 27) + sh.Cells(x.Row, 29) ' grade 1com
.Add , , sh.Cells(x.Row, 31) + sh.Cells(x.Row, 33) + sh.Cells(x.Row, 35) ' grade 2 com
.Add , , sh.Cells(x.Row, 37) + sh.Cells(x.Row, 41) ' grade 3 com
.Add , , sh.Cells(x.Row, 43) ' grade 3B com
.Add , , sh.Cells(x.Row, 45) ' grade pal
.Add , , sh.Cells(x.Row, 47) + sh.Cells(x.Row, 49) + sh.Cells(x.Row, 51) + sh.Cells(x.Row, 53) + sh.Cells(x.Row, 55) + sh.Cells(x.Row, 57) ' grade autre
.Add , , sh.Cells(x.Row, 177) 'coût
.Add , , sh.Cells(x.Row, 8) 'Fournisseur
End With
End If

Next
Next
End With




ListView1.Sorted = False
ListView1.SortKey = 0
'ListView1.SortOrder = lvwAscending
ListView1.Sorted = True

TextBox5.Value = Date

End Sub
3
Rejoignez-nous