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
| Option Explicit
Private Collec1 As New Collection
Private Collec2 As New Collection
Private derli1 As Long
Private derli2 As Long
Private Sub ComboBox1_Change()
On Error Resume Next
Collec1.Add Item:=ComboBox1.Text, Key:=ComboBox1.Text
If Err.Number = 0 Then _
Sheets("Feuille masquée").Range("A" & derli1 + 1) = ComboBox1.Text
End Sub
Private Sub ComboBox2_Change()
On Error Resume Next
Collec2.Add Item:=ComboBox2.Text, Key:=ComboBox2.Text
If Err.Number = 0 Then _
Sheets("Feuille masquée").Range("B" & derli2 + 1) = ComboBox2.Text
End Sub
Private Sub UserForm_Initialize()
Dim C As Range
Dim tabComboBox1 As Variant
Dim tabComboBox2 As Variant
derli1 = Sheets("Feuille masquée").Columns(1).Find("*", , , , , xlPrevious).Row
derli2 = Sheets("Feuille masquée").Columns(2).Find("*", , , , , xlPrevious).Row
tabComboBox1 = Sheets("Feuille masquée").Range("A1:A" & derli1).Value
tabComboBox2 = Sheets("Feuille masquée").Range("B1:B" & derli2).Value
For Each C In Sheets("Feuille masquée").Range("A1:A" & derli1)
Collec1.Add C.Value, CStr(C.Value)
Next C
For Each C In Sheets("Feuille masquée").Range("B1:B" & derli2)
Collec2.Add C.Value, CStr(C.Value)
Next C
ComboBox1.List() = tabComboBox1
ComboBox2.List() = tabComboBox2
ComboBox1.ListIndex = 0
ComboBox2.ListIndex = 0
End Sub |
Partager