|
Private Sub Worksheet_Change(ByVal T As Range)
If T.Row > 10 And T.Column = 2 Then
If T.Count > 1 Then End
If T.Value = "" Then End
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("库存表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b4:c" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = Trim(T.Value) Then
d(Trim(ar(i, 2))) = ""
End If
Next i
T.Offset(, 4).Select ''
With Selection.Validation
.Delete '清除原来的有效性
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(d.keys, ",") ''用字典d3关键字建立有效性
End With ''
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal T As Range)
If T.Row > 10 And T.Column = 2 Then
If T.Count > 1 Then End
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("库存表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b4:b" & r)
End With
For i = 2 To UBound(ar)
If Len(Trim(ar(i, 1))) = 5 Then
d(Trim(ar(i, 1))) = ""
End If
Next i
T.Select ''
With Selection.Validation
.Delete '清除原来的有效性
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(d.keys, ",") ''用字典d3关键字建立有效性
End With ''
End If
End Sub
|
|