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
| Option Explicit
Dim Cell As Range
Dim Tableau()
Dim TempTab As Variant
Dim i As Integer, j As Integer
Dim boolVerif As Boolean
Dim Ws As Worksheet
Dim NbLignes As Integer
Private Sub UserForm_Initialize()
'Définit la feuille contenant les données
Set Ws = Worksheets("CentreProd")
'Définit le nombre de lignes dans la colonne H
NbLignes = Ws.Range("H65536").End(xlUp).Row
'Remplissage du ComboBox1
Alim_Combo 1
End Sub
Private Sub ComboBox1_Change()
'Remplissage Combo2
Alim_Combo 2, ComboBox1.Value
End Sub
Private Sub ComboBox2_Change()
'Remplissage Combo3
Alim_Combo 3, ComboBox2.Value
End Sub
Private Sub ComboBox3_Change()
'Remplissage Combo4
Alim_Combo 4, ComboBox3.Value
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 = Me.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 A (à partir de la 2eme ligne)
For j = 2 To NbLignes
Obj = Ws.Range("A" & j)
'Remplit le ComboBox sans doublons
If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("A" & 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,
'La sélection du ComboBox2 définit le contenu du ComboBox3
etc...)
For j = 2 To NbLignes
If Ws.Range("A" & j).Offset(0, CbxIndex - 2) = Cible Then
Obj = Ws.Range("A" & 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
'Enlève la sélection dans le ComboBox
Obj.ListIndex = -1
End Sub |
Partager