|
三级联动指点,使用一个字典模仿树形结构:
(我也是菜鸟,根据自己的理解写的!请各位大佬多指正)
Private Sub ListBox1_Click()
ListBox2.List = d(ListBox1.Text).keys
End Sub
Private Sub ListBox2_Click()
ListBox3.List = VBA.Split(d(ListBox1.Text)(ListBox2.Text), ",")
End Sub
Private Sub UserForm_Initialize()
Dim arr(), i As Integer, s$
Dim shi_name As String, xiang_name As String, xian_name As String, sandx_name As String
Set d = CreateObject("scripting.dictionary")
arr = Sheets("字典").Range("a3").CurrentRegion.Value
For i = 2 To UBound(arr)
shi_name = arr(i, 1)
xiang_name = arr(i, 2)
sandx_name = arr(i, 1) & arr(i, 2)
xian_name = arr(i, 3)
If Not d.exists(shi_name) Then
Set d(shi_name) = CreateObject("scripting.dictionary")
d(shi_name)(xiang_name) = xian_name
Else
s = IIf(d(shi_name)(xiang_name) = "", "", ",")
d(shi_name)(xiang_name) = d(shi_name)(xiang_name) & s & xian_name
End If
Next
Me.ListBox1.List = d.keys
End Sub |
|