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
| Option Explicit
Dim Ws As Worksheet
Dim NbLignes As Integer
Dim NoAction As Boolean
Private Sub UserForm_Initialize()
'Définit la feuille contenant les données
Set Ws = Worksheets("Etat")
'Définit le nombre de lignes dans la colonne A
NbLignes = Ws.Range("A65536").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 Alim_Combo(CbxIndex As Integer, Optional Cible As Variant)
Dim j As Integer
Dim Obj As Control
Set Obj = Me.Controls("ComboBox" & CbxIndex)
Obj.Clear
NoAction = True
'alimentation 1ere combobox
If CbxIndex = 1 Then
For j = 5 To NbLignes
Obj = Ws.Range("F" & j)
If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("F" & j)
Next j
'alimentation 2eme combobox
ElseIf CbxIndex = 2 Then
For j = 5 To NbLignes
If Ws.Range("F" & j) = Cible Then
Obj = Ws.Range("G" & j)
If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("G" & j)
End If
Next j
'alimentation 3eme combobox
ElseIf CbxIndex = 3 Then
For j = 5 To NbLignes
If Ws.Range("G" & j) = Cible Then
Obj = Ws.Range("C" & j)
If Obj.ListIndex = -2 Then Obj.AddItem Ws.Range("C" & j)
End If
Next j
End If
On Error Resume Next
Obj.ListIndex = 0
On Error GoTo 0
NoAction = False
End Sub |
Partager