Add item to listbox, but only if it is not already there.
Thanks. That definitely did it!
"Bob Phillips" wrote:
Dim i As Long
Dim j As Long
Dim fOK As Boolean
With Me
For i = 0 To .ColumnSelect.ListCount - 1
If .ColumnSelect.Selected(i) Then
fOK = True
For j = 0 To .ColFilter.ListCount - 1
If .ColumnSelect.List(i) = .ColFilter.List(j) Then
fOK = False
Exit For
End If
Next j
If fOK Then
.ColFilter.AddItem .ColumnSelect.List(i)
Else
MsgBox .ColumnSelect.List(i) & _
" already in list"
End If
End If
Next i
End With
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Mark" wrote in message
...
I am trying to write code so that if an item is selected in one listbox,
it
will be added to another listbox. However, it should only be added if it
does not already exist in the second listbox.
Why is the following code doing nothing. It make logical sense, to me.
For i = 0 To UserForm1.ColumnSelect.ListCount - 1
If UserForm1.ColumnSelect.Selected(i) Then
For j = 0 To UserForm1.ColFilter.ListCount
If UserForm1.ColumnSelect.List(i) <
UserForm1.ColFilter.List(j) Then
UserForm1.ColFilter.AddItem
UserForm1.ColumnSelect.List(i)
End If
Next j
End If
Next i
|