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
|
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([C4:C4], Target) Is Nothing And Target.Count = 1 Then
Set d1 = CreateObject("Scripting.Dictionary")
For Each c In [niveau1]: d1(c.Value) = "": Next c
Target.Validation.Delete
Target.Validation.Add xlValidateList, Formula1:=Join(d1.keys, ",")
End If
'-- niv 2
If Not Intersect([D4:D4], Target) Is Nothing And Target.Count = 1 Then
Set d1 = CreateObject("Scripting.Dictionary")
For Each c In [niveau2]
tmp = c.Offset(0, -1): If tmp = "" Then tmp = c.Offset(0, -1).End(xlUp)
If tmp = Target.Offset(, -1) Then d1(c.Value) = ""
Next c
Target.Validation.Delete
If d1.Count > 0 Then Target.Validation.Add xlValidateList, Formula1:=Join(d1.keys, ",")
End If
'---niv3
If Not Intersect([E4:E4], Target) Is Nothing And Target.Count = 1 Then
Set d1 = CreateObject("Scripting.Dictionary")
For Each c In [niveau3]
If c <> "" Then
tmp = c.Offset(0, -2): If tmp = "" Then tmp = c.Offset(0, -2).End(xlUp)
tmp2 = c.Offset(0, -1): If tmp2 = "" Then tmp2 = c.Offset(0, -1).End(xlUp)
If tmp = Target.Offset(, -2) And tmp2 = Target.Offset(, -1) Then d1(c.Value) = ""
End If
Next c
Target.Validation.Delete
If d1.Count > 0 Then
Target.Validation.Add xlValidateList, Formula1:=Join(d1.keys, ",")
Else
Target = ""
End If
End If
'--- niv 4
If Not Intersect([F4:F4], Target) Is Nothing And Target.Count = 1 Then
Set d1 = CreateObject("Scripting.Dictionary")
For Each c In [niveau4]
If c <> "" Then
tmp = c.Offset(0, -3): If tmp = "" Then tmp = c.Offset(0, -3).End(xlUp)
tmp2 = c.Offset(0, -2): If tmp2 = "" Then tmp2 = c.Offset(0, -2).End(xlUp)
tmp3 = c.Offset(0, -1): If tmp3 = "" Then tmp3 = c.Offset(0, -1).End(xlUp)
If tmp = Target.Offset(, -3) And tmp2 = Target.Offset(, -2) And tmp3 = Target.Offset(, -1) Then d1(c.Value) = ""
End If
Next c
Target.Validation.Delete
If d1.Count > 0 Then
If d1.Count > 0 Then Target.Validation.Add xlValidateList, Formula1:=Join(d1.keys, ",")
Else
Target = ""
End If
End If
End Sub |
Partager