'********************************************************************************************************** ' Name: countListBoxSelectedItems ' ' Description: Function to count the currently selected items on the given ListBox. ' ' Parameters: ' listbox List box controls from MSForms library. ' ' Returns: ' Integer The number of currently selected items on the given ListBox. ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2015-02-25 tm Function created. '********************************************************************************************************** Public Function countListboxSelectedItems(listBox As MSForms.listBox) As Integer Const METHOD_NAME As String = "countListboxSelectedItems" '------------------------------------------------------------------------------------------------------ Dim i As Long '------------------------------------------------------------------------------------------------------ 'Iterate through all the items in the given ListBox. ------------------------------------------------| For i = 0 To listBox.ListCount - 1 '| '| 'For each item check if it is selected. If it is, increment result value by 1. --------------| '| If listBox.selected(i) Then '| '| countListboxSelectedItems = countListboxSelectedItems + 1 '| '| End If '| '| '--------------------------------------------------------------------------------------------| '| '| Next i '| '----------------------------------------------------------------------------------------------------| End Function