|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下。。。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
Application.EnableEvents = False
If Len(Target) = 0 Or InStr(Target, "/") Then
Set d = CreateObject("scripting.dictionary")
arr = [j1].CurrentRegion
For i = 2 To UBound(arr)
d(arr(i, 1)) = arr(i, 1)
Next
Else
Set d = CreateObject("scripting.dictionary")
arr = [j1].CurrentRegion
For i = 2 To UBound(arr)
If arr(i, 1) = Target.Value Then d(arr(i, 2)) = Target.Value & "/" & arr(i, 2)
Next
End If
Key = d.items
ss = Join(Key, ",")
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=ss
.IgnoreBlank = True
.InCellDropdown = True
End With
Set d = Nothing
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Len(Target) = 0 Or InStr(Target, "/") Then
Set d = CreateObject("scripting.dictionary")
arr = [j1].CurrentRegion
For i = 2 To UBound(arr)
d(arr(i, 1)) = arr(i, 1)
Next
Else
Set d = CreateObject("scripting.dictionary")
arr = [j1].CurrentRegion
For i = 2 To UBound(arr)
If arr(i, 1) = Target.Value Then d(arr(i, 2)) = Target.Value & "/" & arr(i, 2)
Next
End If
Key = d.items
ss = Join(Key, ",")
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=ss
.IgnoreBlank = True
.InCellDropdown = True
End With
Set d = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|