B
Benoit
Guest
Bonsoir le Forum,
Je viens quémander un peu d'aide de votre part.
j'ai plusieurs listboxs: 3 sources et une cible.
les sources sont remplies avec des données provenant de plusieurs feuilles et un clic sur la 3ème listbox alimente la 4ème, la cible.
Je souhaite tester les données avant de reorter les données de la listbox source vers une des feuilles qui était elle même une feuille source.
Donc je voudrais empêcher de recréer une ligne déjà existante. J'espère que c'est clair je vous joins ce que j'ai pu écrire en recherchant dans les démos. Si vous pouvez voir ce qui ne va pas ou si vous avez la connaissance d'une démo pouvant m'aider veuillez me le faire savoir. Merci par avance
Private Sub ListBox5_Click()
Dim i As Integer
Dim X As Byte
Dim Y As Variant
Dim KeyString As String, NewString As String
Dim ColHist As Collection
Dim TabHist, Item As Variant
''Dim i As Integer
Set ColHist = New Collection
With Historique
.Range('A1').Sort _
Key1:=.Columns('H'), _
Key2:=.Columns('D'), _
Key3:=.Columns('F'), _
Header:=xlGuess
TabHist = .Range('A2:L' & .Range('A65536').End(xlUp).Row)
End With
Dim TabGeneral() As Variant
Dim jj, zz As Long, XX As Long, YY As Long
Dim c, ci As Byte
On Error Resume Next
ColHist.Add TabHist
For zz = 1 To UBound(TabHist)
ReDim Preserve TabGeneral(11, YY)
For c = 0 To 10
TabGeneral(c, YY) = TabHist(zz, c)
Next c
YY = YY + 1
'End If
'End If
Next zz
' End With
With Me.ListBox6
.ColumnCount = 11
.ColumnWidths = '105;105;105;60;60;60;60;60;60;60;40;50'
End With
For jj = 1 To UBound(TabGeneral, 1)
For i = 0 To Me.ListBox6.ListCount - 1
If Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 1)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 1)) & Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 6)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 3)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 7)) & _
Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 2)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 3)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 4)) & Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 2)) & _
Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 7)) _
= Trim(ListBox6.List(i, 0)) & _
Trim(ListBox6.List(i, 1)) & Trim(ListBox6.List(i, 2)) & Trim(ListBox6.List(i, 3)) & _
Trim(ListBox6.List(i, 4)) & Trim(ListBox6.List(i, 5)) & Trim(ListBox6.List(i, 6)) & _
Trim(ListBox6.List(i, 7)) & Trim(ListBox6.List(i, 8)) & Trim(ListBox6.List(i, 9)) _
Or Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 1)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 1)) & Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 6)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 3)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 7)) & _
Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 2)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 3)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 4)) & Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 2)) & _
Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 7)) = _
Trim(TabGeneral(8, jj)) & _
Trim(TabGeneral(4, jj)) & Trim(TabGeneral(6, jj)) & Trim(TabGeneral(2, jj)) & _
Trim(TabGeneral(11, jj)) & Trim(TabGeneral(9, jj)) & Trim(TabGeneral(10, jj)) & _
Trim(TabGeneral(3, jj)) & Trim(TabGeneral(5, jj)) & Trim(TabGeneral(7, jj)) _
Then
MsgBox ('Cette entrée existe deja')
Exit Sub
End If
Next i
Next jj
With Me.ListBox6
.AddItem Me.ListBox3.List(Me.ListBox3.ListIndex, 1)
.Column(1, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 1)
.Column(2, .ListCount - 1) = Me.ListBox5.List(Me.ListBox5.ListIndex, 6)
.Column(3, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 3)
.Column(4, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 7)
.Column(5, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 2)
.Column(6, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 3)
.Column(7, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 4)
.Column(8, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 2)
.Column(9, .ListCount - 1) = Me.ListBox5.List(Me.ListBox5.ListIndex, 7)
End With
End Sub
Je viens quémander un peu d'aide de votre part.
j'ai plusieurs listboxs: 3 sources et une cible.
les sources sont remplies avec des données provenant de plusieurs feuilles et un clic sur la 3ème listbox alimente la 4ème, la cible.
Je souhaite tester les données avant de reorter les données de la listbox source vers une des feuilles qui était elle même une feuille source.
Donc je voudrais empêcher de recréer une ligne déjà existante. J'espère que c'est clair je vous joins ce que j'ai pu écrire en recherchant dans les démos. Si vous pouvez voir ce qui ne va pas ou si vous avez la connaissance d'une démo pouvant m'aider veuillez me le faire savoir. Merci par avance
Private Sub ListBox5_Click()
Dim i As Integer
Dim X As Byte
Dim Y As Variant
Dim KeyString As String, NewString As String
Dim ColHist As Collection
Dim TabHist, Item As Variant
''Dim i As Integer
Set ColHist = New Collection
With Historique
.Range('A1').Sort _
Key1:=.Columns('H'), _
Key2:=.Columns('D'), _
Key3:=.Columns('F'), _
Header:=xlGuess
TabHist = .Range('A2:L' & .Range('A65536').End(xlUp).Row)
End With
Dim TabGeneral() As Variant
Dim jj, zz As Long, XX As Long, YY As Long
Dim c, ci As Byte
On Error Resume Next
ColHist.Add TabHist
For zz = 1 To UBound(TabHist)
ReDim Preserve TabGeneral(11, YY)
For c = 0 To 10
TabGeneral(c, YY) = TabHist(zz, c)
Next c
YY = YY + 1
'End If
'End If
Next zz
' End With
With Me.ListBox6
.ColumnCount = 11
.ColumnWidths = '105;105;105;60;60;60;60;60;60;60;40;50'
End With
For jj = 1 To UBound(TabGeneral, 1)
For i = 0 To Me.ListBox6.ListCount - 1
If Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 1)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 1)) & Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 6)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 3)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 7)) & _
Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 2)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 3)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 4)) & Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 2)) & _
Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 7)) _
= Trim(ListBox6.List(i, 0)) & _
Trim(ListBox6.List(i, 1)) & Trim(ListBox6.List(i, 2)) & Trim(ListBox6.List(i, 3)) & _
Trim(ListBox6.List(i, 4)) & Trim(ListBox6.List(i, 5)) & Trim(ListBox6.List(i, 6)) & _
Trim(ListBox6.List(i, 7)) & Trim(ListBox6.List(i, 8)) & Trim(ListBox6.List(i, 9)) _
Or Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 1)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 1)) & Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 6)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 3)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 7)) & _
Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 2)) & Trim(Me.ListBox3.List(Me.ListBox3.ListIndex, 3)) & _
Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 4)) & Trim(Me.ListBox4.List(Me.ListBox4.ListIndex, 2)) & _
Trim(Me.ListBox5.List(Me.ListBox5.ListIndex, 7)) = _
Trim(TabGeneral(8, jj)) & _
Trim(TabGeneral(4, jj)) & Trim(TabGeneral(6, jj)) & Trim(TabGeneral(2, jj)) & _
Trim(TabGeneral(11, jj)) & Trim(TabGeneral(9, jj)) & Trim(TabGeneral(10, jj)) & _
Trim(TabGeneral(3, jj)) & Trim(TabGeneral(5, jj)) & Trim(TabGeneral(7, jj)) _
Then
MsgBox ('Cette entrée existe deja')
Exit Sub
End If
Next i
Next jj
With Me.ListBox6
.AddItem Me.ListBox3.List(Me.ListBox3.ListIndex, 1)
.Column(1, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 1)
.Column(2, .ListCount - 1) = Me.ListBox5.List(Me.ListBox5.ListIndex, 6)
.Column(3, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 3)
.Column(4, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 7)
.Column(5, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 2)
.Column(6, .ListCount - 1) = Me.ListBox3.List(Me.ListBox3.ListIndex, 3)
.Column(7, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 4)
.Column(8, .ListCount - 1) = Me.ListBox4.List(Me.ListBox4.ListIndex, 2)
.Column(9, .ListCount - 1) = Me.ListBox5.List(Me.ListBox5.ListIndex, 7)
End With
End Sub