|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub Worksheet_SelectionChange(ByVal target As Range)
- If target.Address <> "$B$2:$G$2" And target.Address <> "$B$3:$G$3" And target.Address <> "$B$4:$G$4" Then Exit Sub
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("数据源").[a1].CurrentRegion
- For i = 2 To UBound(arr)
- x = arr(i, 2)
- If Not d.exists(x) Then
- Set d(x) = CreateObject("Scripting.Dictionary")
- d(x)(arr(i, 3) & "") = arr(i, 4)
- ElseIf InStr("," & d(x)(arr(i, 3) & "") & ",", "," & arr(i, 4) & ",") = 0 Then
- d(x)(arr(i, 3) & "") = d(x)(arr(i, 3) & "") & "," & arr(i, 4)
- End If
- Next i
- With target.Validation
- .Delete
- Select Case target.Address
- Case "$B$2:$G$2"
- .Add xlValidateList, , , Join(d.keys, ",")
- [b3:b4] = ""
- Case "$B$3:$G$3"
- .Add xlValidateList, , , Join(d([B2].Value).keys, ",")
- [b4] = ""
- Case "$B$4:$G$4"
- .Add xlValidateList, , , d([B2].Value)([B3].Value)
- End Select
- End With
- On Error Resume Next
- SendKeys "%{down}" '发送到下级
- 'http://www.excelpx.com/thread-375699-3-1.html
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|