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
| Option Explicit
Dim Ws As Worksheet
Dim NbLignes As Integer
Private Sub ComboBox1_Change()
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem
Set Ws = Worksheets("donnee_Commune")
NbLignes = Ws.Range("A65536").End(xlUp).Row
'Remplissage du ComboBox1
Alim_Combo 1
End Sub
'Procédure pour alimenter les ComboBox
Private Sub Alim_Combo(CbxIndex As Integer, Optional Cible As Variant)
Dim j As Integer
Dim Obj As Control
'Définit le ComboBox à remplir
Set Obj = UserForm1.Controls("ComboBox" & CbxIndex)
'Supprime les anciennes données
Obj.Clear
'alimente le Combobox initial (Combobox1)
If CbxIndex = 1 Then
'Boucle sur les lignes de la colonne E (à partir de la 2eme ligne)
For j = 2 To NbLignes
Obj = Ws.Range("E" & j)
'Remplit le ComboBox sans doublons
If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("E" & j)
Next j
Else
'Alimentation conditionnelle des autres Combobox en fonction de
'ce qui est sélectionnée dans le contrôle précédent:
'(La sélection du ComboBox1 définit le contenu du ComboBox2,
'On a une selection en cascade)
For j = 2 To NbLignes
If Ws.Range("E" & j).Offset(0, CbxIndex - 2) = Cible Then
Obj = Ws.Range("E" & j).Offset(0, CbxIndex - 1)
If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & j).Offset(0, CbxIndex - 1)
End If
Next j
End If |
Partager