Check if an item in a ListBox has been selected

0

I have a ListBox1 q list of a ChckBox1 checkbox in a UserForm. I want to enable or disable the checkbox ( CheckBox1.Enabled = True/False if any items in the list are selected.

The checkbox is disabled initially, but if something is selected, I want it to be enabled for dialing.

At the moment I am using a validation loop, but I would like to know if there is a more direct way, without having to analyze item by item.

Private Sub ListBox1_Change()

    Dim s As Boolean: s = False
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            s = True
            Exit For
            End If
        Next i
    CheckBox1.Enabled = s

End Sub
    
asked by anonymous 27.04.2017 / 22:11

1 answer

-1

Use:

Private Sub ListBox1_Change()
Dim s As Boolean: s = False

If ListBox1.ListIndex <> -1 Then
   s = True
End If

CheckBox1.Enable = s
    
16.12.2017 / 06:06