1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| Dim Dico As Object
Private Sub Bt_Valider_Click()
'Private Sub CommandButton1_Click()
Dim I As Integer, y As Integer
y = Cells(Rows.Count, 1).End(xlUp).Row
If y = 1 Then y = 0
With Me.ListBox1
For I = 0 To .ListCount - 1
If .Selected(I) = True Then
y = y + 1
Range("A" & y).Value = .List(I)
End If
Next I
End With
With Me.ListBox2
For I = 0 To .ListCount - 1
If .Selected(I) = True Then
y = y + 1
Range("a" & y).Value = .List(I)
End If
Next I
End With
With Me.ListBox3
For I = 0 To .ListCount - 1
If .Selected(I) = True Then
y = y + 1
Range("a" & y).Value = .List(I)
End If
Next I
End With
For I = 0 To Me.ListBox1.ListCount - 1
Me.ListBox1.Selected(I) = False
Next I
For I = 0 To Me.ListBox2.ListCount - 1
Me.ListBox2.RemoveItem 0
Next I
For I = 0 To Me.ListBox3.ListCount - 1
Me.ListBox3.RemoveItem 0
Next I
End Sub
Private Sub CommandButton2_Click()
Dim I As Integer
With Me.ListBox1
For I = 0 To .ListCount - 1
If .Selected(I) = True Then
[C1] = [C1] & " " & .List(I)
End If
Next I
End With
End Sub
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
'Private Sub ListBox1_Change()
' Dim C As Range, Ligne As Long
' With Feuil2
' .[F:F].ClearContents
' For I = 0 To Me.ListBox1.ListCount - 1
' If Me.ListBox1.Selected(I) Then
' For Each C In .Range("C1", .Cells(.Rows.Count, 3).End(xlUp))
' If C.Value = Me.ListBox1.List(I) Then
' If Application.CountIf(.[F:F], C.Offset(, 1).Value) = 0 Then
' Ligne = Ligne + 1
' .Cells(Ligne, 6).Value = C.Offset(, 1).Value
' End If
' End If
' Next C
' End If
' Next I
' Me.ListBox2.RowSource = "=Feuil2!" & .Range("F1", .Cells(.Rows.Count, 6).End(xlUp)).Address
' End With
'End Sub
Private Sub ListBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim C As Range, Ligne As Long
' Dico.RemoveAll
With Feuil2
Var = Dico.keys
For I = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(I) Then
For Each C In .Range("C1", .Cells(.Rows.Count, 3).End(xlUp))
For j = 1 To UBound(Var)
If C.Value = Me.ListBox1.List(I) And Split(Var(j), "|")(0) = C.Value And _
Split(Var(j), "|")(1) = C.Offset(, 1).Value Then
Me.ListBox3.AddItem C.Offset(, 2).Value
End If
Next j
Next C
End If
Next I
End With
End Sub
Private Sub ListBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim C As Range, Ligne As Long
With Feuil2
.[F:G].ClearContents
For I = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(I) Then
For Each C In .Range("C1", .Cells(.Rows.Count, 3).End(xlUp))
If C.Value = Me.ListBox1.List(I) Then
If Not Dico.exists(C.Value & "|" & C.Offset(, 1).Value) Then
Dico.Add C.Value & "|" & C.Offset(, 1).Value, C.Value & "|" & C.Offset(, 1).Value
Me.ListBox2.AddItem C.Offset(, 1).Value
End If
End If
Next C
End If
Next I
End With
End Sub
Private Sub UserForm_Initialize()
Set Dico = CreateObject("Scripting.Dictionary")
Me.ListBox1.ListIndex = -1
Me.ListBox2.ListIndex = -1
Me.ListBox3.ListIndex = -1
End Sub |
Partager