I have been using the Function below to extract items from a Listbox. After extracting the items, they are then put within a comment of a cell. Moving strData into a Comment works fine, the issue is that the Function does not always pick up all of the items that are placed within it.
If Items are just added from one ListBox1 to Listbox2 and then moved to the Cell Comment, it will pick up all of the items. Because, the user also has the option to Remove an Item, if one of the items in ListBox2 has been selected (highlighted) and then the procedure run, this function leaves the one Listbox item that is highlighted from being recorded.
.ListCount correctly shows the number of items in Listbox2. How do I modify this Function so that it will record all the Items whether one is highlighted or not?
Function GetSelectedItems(lstItems As MsForms.ListBox, Optional strDelimiter As String = ",") As String
Dim lngIndex As Long, strData As String
For lngIndex = 1 To .ListCount
If .Selected(lngIndex - 1) = False Then
strData = strData & strDelimiter & lstItems.List(lngIndex - 1)
GetSelectedItems = Mid$(strData, Len(strDelimiter) + 1)