|
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nL%
nL = Target.Column
If Target.Row = 1 Or nL < 6 Or nL > 8 Or Target.CountLarge > 1 Then Exit Sub '修改4
Application.EnableEvents = False
Target.Offset(0, 1).Resize(1, 9 - nL).ClearContents '修改5
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sj(), nL%, cTxt$, nRow%, Arr(), ds As Object
Set ds = CreateObject("Scripting.Dictionary")
nL = Target.Column - 5 '修改1
If Target.Row = 1 Or nL < 1 Or nL > 4 Or Target.CountLarge > 1 Then Exit Sub '修改2
sj = Range("f" & Target.Row).Resize(1, 3).Value '修改3
With Sheets("基础")
nRow = .Cells(999, nL).End(xlUp).Row
Arr = .Range("a1").Resize(nRow, nL).Value
End With
For i = 2 To nRow
For j = 1 To nL - 1
If Arr(i, j) <> sj(1, j) Then Exit For
Next
If j = nL And Not ds.exists(Arr(i, nL)) Then
ds(Arr(i, nL)) = ""
cTxt = cTxt & "," & Arr(i, nL)
End If
Next
With Target.Validation
.Delete
If cTxt <> "" Then .Add 3, 1, 1, Mid(cTxt, 2)
End With
End Sub
|
|