Validation de données avec liste déroulante en cascade
24 réponses
Apitos
Bonjour =E0 tous,
J'aimerais lier une liste d=E9roulante de choix en colonne C avec une liste=
de validation de donn=E9es en colonne B.
Quand un choix est fait en colonne B, automatiquement une liste d=E9roulant=
e est cr=E9=E9e en colonne C si on a plus d'une occurrence qui correspond a=
u choix effectu=E9 dans la liste de validation.
2 autres alternatives, choisis celle qui te convient.
Dans une petite procédure comme celle-ci, la présence d'un "Si" de plus ou moins n'a pas grande incidence sur le temps de traitement de la procédure...!
Traite seulement une cellule à la fois, celle qui est active en colonne B '----------------------------------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) Dim X As Variant If Target.Cells.Count = 1 Then If Target.Column = 2 And Target <> "" Then With Worksheets("Listes") X = Application.Match(Target, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0) If Not IsError(X) Then Application.EnableEvents = False Target.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X) Application.EnableEvents = True End If End With End If End If End Sub '-----------------------------------------------------------------------------------------
OU
Traite toutes les cellules sélectionnées de la colonne B. '----------------------------------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) Dim X As Variant, Rg As Range, C As Range Set Rg = Intersect(Range("B:B"), Target) If Not Rg Is Nothing Then For Each C In Rg If C <> "" Then With Worksheets("Listes") X = Application.Match(C.Value, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0) If Not IsError(X) Then Application.EnableEvents = False C.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X) Application.EnableEvents = True End If End With End If Next End If End Sub '-----------------------------------------------------------------------------------------
2 autres alternatives, choisis celle qui te convient.
Dans une petite procédure comme celle-ci, la présence d'un "Si"
de plus ou moins n'a pas grande incidence sur le temps de traitement
de la procédure...!
Traite seulement une cellule à la fois, celle qui est active en colonne B
'-----------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Variant
If Target.Cells.Count = 1 Then
If Target.Column = 2 And Target <> "" Then
With Worksheets("Listes")
X = Application.Match(Target, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0)
If Not IsError(X) Then
Application.EnableEvents = False
Target.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X)
Application.EnableEvents = True
End If
End With
End If
End If
End Sub
'-----------------------------------------------------------------------------------------
OU
Traite toutes les cellules sélectionnées de la colonne B.
'-----------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Variant, Rg As Range, C As Range
Set Rg = Intersect(Range("B:B"), Target)
If Not Rg Is Nothing Then
For Each C In Rg
If C <> "" Then
With Worksheets("Listes")
X = Application.Match(C.Value, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0)
If Not IsError(X) Then
Application.EnableEvents = False
C.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X)
Application.EnableEvents = True
End If
End With
End If
Next
End If
End Sub
'-----------------------------------------------------------------------------------------
2 autres alternatives, choisis celle qui te convient.
Dans une petite procédure comme celle-ci, la présence d'un "Si" de plus ou moins n'a pas grande incidence sur le temps de traitement de la procédure...!
Traite seulement une cellule à la fois, celle qui est active en colonne B '----------------------------------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) Dim X As Variant If Target.Cells.Count = 1 Then If Target.Column = 2 And Target <> "" Then With Worksheets("Listes") X = Application.Match(Target, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0) If Not IsError(X) Then Application.EnableEvents = False Target.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X) Application.EnableEvents = True End If End With End If End If End Sub '-----------------------------------------------------------------------------------------
OU
Traite toutes les cellules sélectionnées de la colonne B. '----------------------------------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) Dim X As Variant, Rg As Range, C As Range Set Rg = Intersect(Range("B:B"), Target) If Not Rg Is Nothing Then For Each C In Rg If C <> "" Then With Worksheets("Listes") X = Application.Match(C.Value, .Range("A2:A" & .Range("A65536").End(xlUp).Row), 0) If Not IsError(X) Then Application.EnableEvents = False C.Offset(0, 1) = .Range("B2:B" & .Range("B65536").End(xlUp).Row).Item(X) Application.EnableEvents = True End If End With End If Next End If End Sub '-----------------------------------------------------------------------------------------