EASY:VBA:期待通过列表框,选择的内容期待、内容、列表、EASY

2023-09-08 11:28:59 作者:相关男生个性昵称>>

我知道这是很简单的东西,它的滑落我的我的现在。我怎么循环,虽然一个列表框,选择的内容?

这里的code我做了现在:

 昏暗allGrps作为整数
昏暗我作为整数
allGrps = lstAllGroups.ListCount
对于i = 1到allGrps
lstAllGroups
下一个
 

解决方案

请记住,列表框的索引从零开始,所以你一定要减一关,从我:

 对于i = 1到allGrps
    lstAllGroups.Selected(I  -  1)=真
接下来我
 
excel vba 列表框

另外,还要确保你有 SelectSheetsList.MultiSelect = fmMultiSelectMulti ,以便能够在列表中选择多个项目。

请参阅 ListBox中的文档了解更多信息。

I know this is something really simple and it's slipping my mine right now. how do I loop though a listbox and select the contents?

Here's the code I've made right now:

Dim allGrps As Integer
Dim i As Integer
allGrps = lstAllGroups.ListCount
For i = 1 To allGrps
lstAllGroups
Next

解决方案

Keep in mind that the listbox is zero-indexed so you've got to subtract one off from i:

For i = 1 To allGrps
    lstAllGroups.Selected(i - 1) = True
Next i

Also, make sure you've got SelectSheetsList.MultiSelect = fmMultiSelectMulti in order to be able to select multiple items in the list.

See the ListBox documentation for more info.