扼杀动态列表索引

时间:2015-12-17 10:32:11

标签: vba combobox

第一个计时器。随时随地学习VBA并需要一些帮助。我在这行代码Me.Tech2.ListIndex = startnr

上获得了无效的属性值

startnr根据组合框的值而变化" Tech2"。

Dim jobnr As String
Dim startnr As Integer
Dim endnr As Integer

'Tech2 combobox populates according to the name in Tech1 combobox where the name is a named range

jobnr = Tech1.Value
Sheets("Lists").Activate        'named range scope are sheets("Lists")'
Me.Tech2.RowSource = jobnr
endnr = 10000

 If Me.Tech2 = "" Then
     For startnr = 1 To endnr
     Next startnr
 End If

Me.Tech2.ListIndex = startnr

1 个答案:

答案 0 :(得分:0)

startnr10001,因此Me.Tech2.ListIndex = startnr会尝试将所选项目设为Tech2中的第10,002项,如果该项目不存在,则会引发错误。

ListIndex的有效值为0,最后一项为Me.Tech2.ListCount - 1的第一项。