excel vba窗体的复合框,怎么能默认选中第一项?
我做了一个多级的下拉菜单,根据combobox1和combobox2的选择情况,combobox3的下拉列表也会发生变化。我想在每次改变combobox1或者combob...
我做了一个多级的下拉菜单,根据combobox1和combobox2的选择情况,combobox3的下拉列表也会发生变化。我想在每次改变combobox1或者combobox2的时候。combobox3会默认选择当前可选列表中的第一项。求高手解答~~
展开
展开全部
可以通过设置其value属性来给组合框赋值,示例代码如下
Private Sub ComboBox2_AfterUpdate()
Dim rng As Range
Select Case Me.ComboBox2.ListIndex
Case 0
Set rng = Sheet1.Range("C1:C10")
Case 1
Set rng = Sheet1.Range("D1:D10")
End Select
Me.ComboBox3.RowSource = rng.Worksheet.Name & "!" & rng.Address
Me.ComboBox3.Value = Application.WorksheetFunction.Index(rng, 1)
End Sub
Private Sub ComboBox2_AfterUpdate()
Dim rng As Range
Select Case Me.ComboBox2.ListIndex
Case 0
Set rng = Sheet1.Range("C1:C10")
Case 1
Set rng = Sheet1.Range("D1:D10")
End Select
Me.ComboBox3.RowSource = rng.Worksheet.Name & "!" & rng.Address
Me.ComboBox3.Value = Application.WorksheetFunction.Index(rng, 1)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询