![](/img/trans.png)
[英]Selected value in combo box to open another worksheet in Excel VBA/User form
[英]Excel VBA: Looping through a combo box's items from another user form
我想遍历组合框的项目,但不获取其值。 我只想遍历有多少个项目。 这是我向其中添加项目的方式。
Private Sub UserForm_Initialize()
Chapter.AddItem "Chapter 1"
Chapter.AddItem "Chapter 2"
Chapter.AddItem "Chapter 3"
Chapter.AddItem "No Chapter"
End Sub
这就是我尝试遍历的内容。
Dim itm As Object
For Each itm In UserForm.ComboBox1.Items.Count
Next
但是错误提示; 编译错误:找不到方法或数据成员
这些代码不在一种用户表单上是否重要? 我有两个用户窗体,将项目添加到组合框中是第二个,通过组合框的循环是第一个。 有关系吗
试试这个(不声明为对象):
For Each itm In ComboBox1.List
'for example display in messagebox
MsgBox itm
Next
如果您只想循环计算项目数,则可以尝试
Dim itm As Object
For i = 1 to UserForm1.Chapter.ListCount
Next
其中Userform1
是包含组合框的窗体的名称,而Chapter
是组合框的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.