VBA - 列表框删除所有选中和下一个全选

时间:2017-09-25 22:45:31

标签: excel vba select listbox

有人可以告诉我为什么这段代码不会读取代码中的第一个代码。我正在尝试删除我手动选择的列表中的所有项目,这是有效的,但之后我希望它全部被选中,所以我可以将孔列表写入工作表,但无论我做什么,我都可以'从列表中删除项目后,将其全部选中。事实上它不会读过第一个下一个我怎么知道,因为如果我在它之前设置清除功能将清除工作表但不是如果我把它放在下一个代码之后。

Private Sub CommandButton2_Click()
    For listIndexCount = 0 To ListBox1.ListCount
        If listIndexCount >= ListBox1.ListCount Then
            Exit Sub
        End If
        If ListBox1.Selected(listIndexCount) Then
            ListBox1.RemoveItem (listIndexCount)
            listIndexCount = listIndexCount - 1
        End If
    Next listIndexCount 
    Sheets("Courses_calc").Cells.Clear
    For i = 0 To ListBox1.ListCount - 1
        ListBox1.Selected(i) = True
    Next i
End Sub

0 个答案:

没有答案