Not sure if anyone needs this, but if you are having problems with .additem i thought maybe you might be having problems with .removeItem as well. here is a code snippet i use to remove items from the list. It takes a list box as a parameter and depending on the number of column heads or columns count it will remove the selected item
Public Sub RemoveItem(lst As ListBox)
Dim strArray() As String
Dim i As Long
Dim lngStart As Long
Dim str As String
strArray = Split(lst.RowSource, ";", , vbTextCompare)
If lst.ColumnHeads Then
lngStart = (lst.ColumnCount * lst.ListIndex) + lst.ColumnCount
Else: lngStart = lst.ColumnCount * lst.ListIndex
End If
For i = 0 To lngStart - 1
str = str & strArray(i) & ";"
Next i
For i = i + lst.ColumnCount To UBound(strArray) - 1
str = str & strArray(i) & ";"
Next i
If i > UBound(strArray) Then
lst.RowSource = Left(str, Len(str) - 1) 'remove last semicolon
Else: lst.RowSource = str & strArray(i)
End If
End Sub
|