• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Listbox Selected Count Wrong

Jeff Slavin

New Member
Hi All - Have the simple function below to count the number of items selected in a ListBox on a UserForm. For some reason every once in awhile the function will return 0 even though there are items selected in the Listbox.

Any help is greatly appreciated.

Best,
Jeff

Code:
Public Function MSR_Form_Listbox_GetSelectedCount(lstListBox As MSForms.ListBox) As Integer
 
    Dim i As Integer
    Dim iSelected As Integer
   
    iSelected = 0
    With lstListBox
        For i = 0 To .ListCount - 1
            If .Selected(i) = True Then iSelected = iSelected + 1
        Next i
    End With
   
    MSR_Form_Listbox_GetSelectedCount = iSelected
 
End Function
 
Back
Top