listbox comment enlever doublon de liste?

pasquetp

XLDnaute Occasionnel
Bonjour,

j'ai une listebox qui marche presque bien mais il doit manquer quelque chose

en lancant le formulaire je vois apparaitre tous les codes en colonne C: il y a deux conditions:

If Cells(L, 6).Interior.Color <> 10025880 And Cells(L, 4) = "Error" Then

les conditions sont respectees ce qui est cool.

toutefois les codes apparaissent a repetition

sauriez vous comment voir que les codes une fois dans le listbox?

Merci de votre aide





Private Sub UserForm_Initialize()
Dim L As Long
For L = 6 To [C65000].End(xlUp).Row
If Cells(L, 6).Interior.Color <> 10025880 And Cells(L, 4) = "Error" Then

If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem Cells(L, 3)
End If
Next
For L = 1 To ComboBox1.ListCount - 1
If ComboBox1.List(L) <> "" Then ListView1.ListItems.Add , , ComboBox1.List(L)
Next
For L = 1 To ListView1.ListItems.Count
ListBox1.AddItem ListView1.ListItems(L)

Next
End Sub
 

Pièces jointes

  • report of errors - simulation.xlsm
    717.2 KB · Affichages: 114
  • report of errors - simulation.xlsm
    717.2 KB · Affichages: 111
  • report of errors - simulation.xlsm
    717.2 KB · Affichages: 126

Staple1600

XLDnaute Barbatruc
Re : listbox comment enlever doublon de liste?

Re

pasquetp
Il faut évidemment adapter la syntaxe à ton classeur ...
Chez toi : For L = 6 To [C65000].End(xlUp).Row
et dans l'exemple du lien que je t'ai donné
For Each c In Sheets("Feuil1").Range("A1:A" & Range("a65536").End(xlUp).Row)
Tu vois ou je veux en venir ?

Ma foi, être un chouia curieux et perspicace, face à une erreur, c'est indolore...;)


 

pasquetp

XLDnaute Occasionnel
Re : listbox comment enlever doublon de liste?

Re

merci de votre reponse

j'ai tenté ce code

PrivateSub UserForm_Initialize()
Dim c As Range
Dim tablo()
Dim i As Integer, j As Integer
Dim temp As String
Dim present As Boolean

ReDim tablo(1 To 1)
tablo(1) = Cells(1, 1)
For Each c In Sheets("error-report").Range("C6:C" & Range("C65536").End(xlUp).Row)
present = False
For i = 1 To UBound(tablo)
If tablo(i) = c Then present = True
Next i
If Not present Then
ReDim Preserve tablo(1 To UBound(tablo) + 1)
tablo(UBound(tablo)) = c
End If
For i = 1 To UBound(tablo)
For j = 1 To UBound(tablo)
If tablo(i) < tablo(j) Then
temp = tablo(i)
tablo(i) = tablo(j)
tablo(j) = temp
End If
Next j
Next i
Next c

ListBox1.List = tablo

End Sub


La boucle tourne indefiniment.

le code est trop complique a mon niveau

Je vous remercie de l'aide que vous pouvez m'apporter
 

Statistiques des forums

Discussions
312 196
Messages
2 086 101
Membres
103 116
dernier inscrit
kutobi87