|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'代码来源: [求助]大数据量,多级下拉菜单速度问题https://club.excelhome.net/thread-328961-1-1.html(出处: ExcelHome技术论坛)
'代码参考: 多级菜单(数据有效性)终极方案【VBA】https://club.excelhome.net/thread-1510919-1-1.html(出处: ExcelHome技术论坛)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nL%
nL = Target.Column
If Target.Row = 1 Or nL < 1 Or nL > 6 Or Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1).Resize(1, 7 - nL).ClearContents
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sj(), cTxt$, Arr(), sj2(1 To 7), nRow&, nL&
If Target.Row = 1 Or Target.Column < 1 Or Target.Column > 7 Or Target.CountLarge > 1 Then Exit Sub
nL = Target.Column
sj = Range("a" & Target.Row).Resize(1, 7).Value
With Sheets("地址")
nRow = .Cells(1048576, 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) <> "" Then
If cTxt <> "" Then
i = nRow
Exit For
End If
sj2(j) = Arr(i, j)
End If
If sj2(j) <> sj(1, j) Then Exit For
Next
If j = nL And Arr(i, nL) <> "" Then
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
|
|