|
本帖最后由 活在理想的世界 于 2017-9-25 18:17 编辑
我明白你的意思了,是不能改对吗?用下面的代码吧,下面的没问题了。- Private Sub Worksheet_Change(ByVal Target As Range)
- Application.EnableEvents = False
- Dim dic As Object, eic As Object, arr()
- k = Sheet2.Range("a1048576").End(3).Row - 1
- x = Sheet1.Range("a1048576").End(3).Row - 1
- Set dic = CreateObject("Scripting.Dictionary")
- Set eic = CreateObject("Scripting.Dictionary")
- arr = Sheet2.Range("a2").Resize(k, 2)
- For i = 1 To UBound(arr)
- dic(arr(i, 1)) = ""
- Next
- If x = 0 Then
- Sheet1.Range("a" & x + 2).Validation.Delete
- Sheet1.Range("a" & x + 2).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(dic.Keys, ",")
- Else
- Sheet1.Range("a" & Target.Row + 1).Validation.Delete
- Sheet1.Range("a" & Target.Row + 1).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(dic.Keys, ",")
- End If
- On Error Resume Next
- For i = 1 To UBound(arr)
- If Sheet1.Range("a" & Target.Row) = arr(i, 1) Then
- eic(arr(i, 2)) = ""
- End If
- Next
- Sheet1.Range("b" & Target.Row).Validation.Delete
- Sheet1.Range("b" & Target.Row).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(eic.Keys, ",")
- Application.EnableEvents = True
- End Sub
复制代码
|
|