|
楼主 |
发表于 2014-8-5 16:41
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
aman1516 发表于 2014-8-5 10:46
谢谢分享,树形 多级有效性 中点击E列时出错(光是调小列距或隐藏不是办法),还是用个容错代码或判断解决 ...
加一点容错代码即可:- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Dim str$, k&
- If Target.Cells.count > 1 Then Exit Sub
- If Target.Column > 1 Then
- If Target.Offset(0, -1).Value = "" Then Exit Sub
- End If
- With mt '树初始化
- .count = 0
- Set .d = Nothing
- Erase .md
- End With
- Call buildTree '建树
- If Target.Column = 1 Then
- With Target.Validation
- .Delete
- .Add 3, 1, 1, Join(mt.root, ",")
- End With
- End If
- If Target.Column > 1 Then
- With Target.Validation
- .Delete
- str = ""
- For k = 1 To Target.Column
- str = str & "" & Target.Offset(0, k - Target.Column).Value
- Next
- With mt
- str = Right(str, Len(str) - 1)
- If .d.Exists(str) Then
- str = .md(.d(str)).mParent
- str = Replace(.md(.d(str)).son, "~#", ",")
- Else
- str = ""
- End If
- End With
- If str <> "" Then .Add 3, 1, 1, str
- End With
- End If
- End Sub
复制代码 |
|