Select All Item of ListBox by Check Box

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 Long
    For r = 1 To Me.ListBox1.ListCount - 1
    If Me.CheckBox1 = True Then
    Me.ListBox1.Selected(r) = True
   
    Else
     Me.ListBox1.Selected(r) = False
    End If
    Next
End Sub



Now click on Check Box to Select all Items of ListBox


 

No comments:

Post a Comment