|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
各位老师好,请帮忙看下工作表中的两个代码,怎样才能同时运行不冲突,谢谢!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect([A2], Target) Is Nothing Then Exit Sub
Dim arr, i&, s
Dim d As Object
Set d = CreateObject("scripting.dictionary") '后期字典
arr = Sheets("客户").Range("A1:A" & Cells(Rows.Count, "A").End(4).Row) '数据来源列
For i = 2 To UBound(arr) 'D1是标题,从第2行开始遍历数据源,装入字典
If arr(i, 1) <> "" Then d(arr(i, 1)) = ""
Next
s = Join(d.keys, ",")
With Target.Validation
.Delete '删掉旧的
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=s 'S为数据验证的序列来源
End With
'Application.SendKeys "%{down}" '加这个代码,鼠标放上去直接伸出下拉菜单atl+↓直接弹出数据验证下拉列表
Set d = Nothing '释放字典
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect([B2], Target) Is Nothing Then Exit Sub
Dim brr, k&, j
Dim a As Object
Set a = CreateObject("scripting.dictionary") '后期字典
brr = Sheets("数据库").Range("a1:a" & Cells(Rows.Count, "a ").End(4).Row) '数据来源列
For i = 2 To UBound(arr) 'D1是标题,从第2行开始遍历数据源,装入字典
If brr(k, 1) <> "" Then a(brr(k, 1)) = ""
Next
j = Join(d.keys, ",")
With Target.Validation
.Delete '删掉旧的
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=j 'S为数据验证的序列来源
End With
'Application.SendKeys "%{down}" '加这个代码,鼠标放上去直接伸出下拉菜单atl+↓直接弹出数据验证下拉列表
Set a = Nothing '释放字典
End Sub
|
|