Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What if I were trying to remove an item that was in the second box?
Private Sub cRemove_Click() ' Remove items that were added to the ColFilter list box, but which ' are no longer desired as part of the report 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 = False For j = 0 To .ColFilter.ListCount - 1 If .ColumnSelect.List(i) < .ColFilter.List(j) Then fOK = True Exit For End If Next j If fOK Then .ColFilter.RemoveItem .ColumnSelect.List(i) Else MsgBox (.ColumnSelect.List(i) & " is not part of the report columns.") End If End If Next i End With End Sub "Mark" wrote: 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() -- 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Last Item of Listbox not getting displayed | Excel Discussion (Misc queries) | |||
Item order in ListBox | Excel Discussion (Misc queries) | |||
listbox remove Item | Excel Programming | |||
Opening item from Listbox... Need Help :P | Excel Programming | |||
The value of a ListBox Item | Excel Programming |