|
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.UsedRange
For i = 2 To UBound(arr)
d(arr(i, 1)) = ""
Next
k = d.keys
For i = 0 To d.Count - 1
f = f & k(i) & ","
Next
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=f
End With
ElseIf Target.Column = 2 Then
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.UsedRange
For i = 2 To UBound(arr)
If arr(i, 1) = Target.Offset(0, -1).Value Then
d(arr(i, 2)) = ""
End If
Next
k = d.keys
For i = 0 To d.Count - 1
f = f & k(i) & ","
Next
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=f
End With
ElseIf Target.Column = 3 Then
Set d = CreateObject("scripting.dictionary")
arr = Sheet1.UsedRange
For i = 2 To UBound(arr)
If arr(i, 1) = Target.Offset(0, -2).Value And arr(i, 2) = Target.Offset(0, -1).Value Then
d(arr(i, 3)) = ""
End If
Next
k = d.keys
For i = 0 To d.Count - 1
f = f & k(i) & ","
Next
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=f
End With
End If
End Sub
|
|