Sometimes we need to select items of ListBox in excel vba. The following VBA code is for select all items of a ListBox by clicking the CheckBox. Here r = 1 To Me.ListBox1.ListCount - 1 means r is a variables that counts 1st row to last row of the listbox
Private Sub CheckBox1_Click()Dim r As LongFor r = 1 To Me.ListBox1.ListCount - 1If Me.CheckBox1 = True ThenMe.ListBox1.Selected(r) = TrueElseMe.ListBox1.Selected(r) = FalseEnd IfNextEnd Sub
Now click on Check Box to Select all Items of ListBox
No comments:
Post a Comment