在excel的窗体中实现多级下拉菜单
1个回答
展开全部
你可以试试,下面是我自己以前弄的窗体三级下拉菜单
Private Sub UserForm_Initialize() '将一级菜单复制,二级和三级的列表为空
Me.ComboBox1.List = Array("中国", "中国人")
End Sub
Private Sub ComboBox1_Change() '当一级菜单的值改变了,将二级菜单赋值
Dim a, b1, b2
b1 = Array("广东", "海南")
b2 = Array("广东人", "海南人")
If ComboBox1.Text = "" Then
Exit Sub
Else
If ComboBox1.Text = "中国" Then
Me.ComboBox2.List = b1
Else
Me.ComboBox2.List = b2
End If
End If
End Sub
Private Sub ComboBox2_Change() '当二级菜单的值改变了,将三级菜单赋值
Dim a, b1, b2
b1 = Array("广州", "深圳")
b2 = Array("海口", "三亚")
b3 = Array("广州人", "深圳人")
b4 = Array("海口人", "三亚人")
If ComboBox2.Text = "" Then
Exit Sub
Else
If ComboBox2.Text = "广东" Then
Me.ComboBox3.List = b1
ElseIf ComboBox2.Text = "海南" Then
Me.ComboBox3.List = b2
ElseIf ComboBox2.Text = "广东人" Then
Me.ComboBox3.List = b3
ElseIf ComboBox2.Text = "海南人" Then
Me.ComboBox3.List = b4
End If
End If
End Sub
Private Sub UserForm_Initialize() '将一级菜单复制,二级和三级的列表为空
Me.ComboBox1.List = Array("中国", "中国人")
End Sub
Private Sub ComboBox1_Change() '当一级菜单的值改变了,将二级菜单赋值
Dim a, b1, b2
b1 = Array("广东", "海南")
b2 = Array("广东人", "海南人")
If ComboBox1.Text = "" Then
Exit Sub
Else
If ComboBox1.Text = "中国" Then
Me.ComboBox2.List = b1
Else
Me.ComboBox2.List = b2
End If
End If
End Sub
Private Sub ComboBox2_Change() '当二级菜单的值改变了,将三级菜单赋值
Dim a, b1, b2
b1 = Array("广州", "深圳")
b2 = Array("海口", "三亚")
b3 = Array("广州人", "深圳人")
b4 = Array("海口人", "三亚人")
If ComboBox2.Text = "" Then
Exit Sub
Else
If ComboBox2.Text = "广东" Then
Me.ComboBox3.List = b1
ElseIf ComboBox2.Text = "海南" Then
Me.ComboBox3.List = b2
ElseIf ComboBox2.Text = "广东人" Then
Me.ComboBox3.List = b3
ElseIf ComboBox2.Text = "海南人" Then
Me.ComboBox3.List = b4
End If
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询