steve077
Messages postés6Date d'inscriptionvendredi 29 décembre 2006StatutMembreDernière intervention29 juin 2008
-
23 juin 2008 à 17:40
steve077
Messages postés6Date d'inscriptionvendredi 29 décembre 2006StatutMembreDernière intervention29 juin 2008
-
23 juin 2008 à 18:44
Bonjour
Je voudrais supprimer les doublons dans un contrôle de 6 listbox nommées List1(0) ,List1(1) ... ,List1(5)
Le problème c'est que ma fonction tourne en boucle.
Je me suis inspiré de ce code : http://www.vbfrance.com/code.aspx?ID=7647
Je vous laisse mon code ci-dessous :
Function VerifDoublon()
Dim iPos As Integer
iPos = 0
If Form2.List1(5).ListCount < 1 Then Exit Function 'Si la listbox est vide il quitte la fonction
Do While iPos < Form2.List1(5).ListCount
Form2.List1(5).Text = Form2.List1(5).List(iPos)
'Verifie si le text existe deja
If Form2.List1(5).ListIndex <> iPos Then
If Form2.List1(4).ListIndex <> iPos Then
If Form2.List1(3).ListIndex <> iPos Then
If Form2.List1(2).ListIndex <> iPos Then
If Form2.List1(1).ListIndex <> iPos Then
If Form2.List1(0).ListIndex <> iPos Then
'Si c 'est le cas il supprime et garde la position iPos...
Form2.List1(5).RemoveItem iPos
Form2.List1(4).RemoveItem iPos
Form2.List1(3).RemoveItem iPos
Form2.List1(2).RemoveItem iPos
Form2.List1(1).RemoveItem iPos
Form2.List1(0).RemoveItem iPos
Else
'Si ce n'est pas le cas il change la position iPos...
iPos = iPos + 1
End If
End If
End If
End If
End If
End If
Loop
Form2.List1(5).Text = "-" 'Utilisé pour désélectionner la dernière ligne
steve077
Messages postés6Date d'inscriptionvendredi 29 décembre 2006StatutMembreDernière intervention29 juin 2008 23 juin 2008 à 18:00
Salut
J'ai réussi en modifiant ton code , merci Mortalino :)
Je met le code modifié si jamais quelqu'un à le même problème un jour :
Sub VerifDoublon()
Dim i As Long, j As Long
For i = 0 To Form2.List1(5).ListCount - 1
For j = Form2.List1(5).ListCount - 1 To i + 1 Step -1
If Form2.List1(5).List(i) = Form2.List1(5).List(j) Then
If Form2.List1(4).List(i) = Form2.List1(4).List(j) Then
If Form2.List1(3).List(i) = Form2.List1(3).List(j) Then
If Form2.List1(2).List(i) = Form2.List1(2).List(j) Then
If Form2.List1(1).List(i) = Form2.List1(1).List(j) Then
If Form2.List1(0).List(i) = Form2.List1(0).List(j) Then