【发布时间】:2012-11-13 21:56:05
【问题描述】:
我有两个组合框。第一个组合框有三个项目:{One, Tow, Three} 现在我想根据用户在 combobox1 中选择的内容加载第二个组合框。 例如,如果用户在 from combobox1 中选择 One,则 namebox1 将填充到combox2 如果用户在 from combobox2 中选择两个,则 namebox2 将填充到combox2 等等.. 你能告诉我如何在 VBA 中做到这一点吗?
谢谢
这里是更新代码:
Private Sub ComboBox1_Change()
Me.ComboBox2.Clear
Select Case Me.ComboBox1.Value
Case "One"
With Me.ComboBox2
.RowSource = "nameBox1"
End With
Case "Two"
With Me.ComboBox2
.RowSource = "nameBox1"
End With
Case "Three"
With Me.ComboBox2
.RowSource = "nameBox1"
End With
End Select
End Sub
请注意,我没有使用 .addItem 来填充 ComboBox1。它已通过相同的方法填充。RowSource 是使用 excel 集合选择框
【问题讨论】: