Counting items in a Multi-Selection Listbox (Quickie)

diamondgeezer1974

Board Regular
Joined
Oct 11, 2004
Messages
161
I have a multi-Selection list box, and a label that says "0 names selected".

What do I use, if the user selects 3 names in the listbox, in order for the label to say "3 names selected".

ListIndex, tells me whats been selected, and ListCount tells me how many items in the list.......but what tells me how many items have been selected?

Thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Here is an example:

Code:
Private Sub ListBox1_Change()
    Dim i As Integer
    Dim Counter As Integer
    Counter = 0
    With ListBox1
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                Counter = Counter + 1
            End If
        Next i
    End With
    Label1.Caption = Counter & " items selected"
End Sub
 
Upvote 0
Sorry but there's no property that will return a count of the no of items selected.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top