Updates a comma-separated text in a TextBox, adding newly selected values in a ListBox or removing deselected ones, leaving everything not in the ListBox untouched.
Private Sub UpdateMe(List As ListBox, Items As TextBox) Dim MergedData As String Dim iArray As Variant Dim nArray As Variant Dim Found As Boolean If (Not IsNull(Items.Value)) Then MergedData = Items.Value iArray = Split(MergedData, ",", -1, vbTextCompare) Else iArray = Array() End If nArray = Array("PRE") For intI = 0 To List.ListCount If List.Selected(intI) Then nArray = Split(Join(nArray, ",") & "," & List.ItemData(intI), ",", -1, vbTextCompare) End If Next intI For Each curItem In iArray curItem = Trim(curItem) Found = False For intI = 0 To List.ListCount If List.ItemData(intI) = curItem Then Found = True End If Next intI If Not Found Then nArray = Split(Join(nArray, ",") & "," & curItem, ",", -1, vbTextCompare) Next curItem MergedData = Join(nArray, ", ") MergedData = Replace(MergedData, "PRE, ", "") MergedData = Replace(MergedData, "PRE", "") Items.Value = MergedData End Sub