View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Tibbetts Jim Tibbetts is offline
external usenet poster
 
Posts: 74
Default Moving name from 1 listbox to another

Tom - As always, thanks for the quick reply. I modified your code slightly to
reflect the names of the listboxes. Here is what I have:

Private Sub TeamListBox_Click()
For i = 0 To TeamListBox.ListCount - 1
If TeamListBox.Selected(i) Then
DropsListBox.AddItem TeamListBox.List(i) ***
End If
Next
For i = TeamListBox.ListCount - 1 To 0 Step -1
If TeamListBox.Selected(i) Then
TeamListBox.Selected(i) = False
TeamListBox.RemoveItem i
End If
Next
End Sub

I get an error "Permission denied" at the 4th line (marked ***). Any ideas?

Jim T


"Tom Ogilvy" wrote:

I would use additem to populate the listboxes rather than use the rowsource.
You will have a hard time removing an item from the list especially from the
click event. This shows how to do it when you use additem to populate and
use a commandbutton to move

Private Sub CommandButton1_Click()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
ListBox2.AddItem ListBox1.List(i)
End If
Next
For i = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(i) Then
ListBox1.Selected(i) = False
ListBox1.RemoveItem i
End If
Next
End Sub

This also assumes the multiselect property of the listboxes has been set to
true.

--
Regards,
Tom Ogilvy


"Jim Tibbetts" wrote in message
...
Hello All - I have 2 ListBoxes on a UserForm. The 1st is populated with a
list of names based on a choice from a ComboBox. How can I "move" a name
from
the 1st box (TeamListBox) to the 2nd box (DropsListBox - RowSource DROPS)
when it is clicked? The following will make the clicked name appear in the
2nd box, but how do I get the name to disappear from the 1st box ?

Private Sub TeamListBox_Click()
Worksheets("TeamData").Select
Range("INDEX(DROPS,1,1)").Select
Dim DropCounter As Integer
For DropCounter = 1 To 10
If ActiveCell.Value = "" Then
ActiveCell.Value = TeamListBox.Value
Exit Sub
Else
ActiveCell.Offset(1, 0).Select
End If
Next DropCounter
End Sub

Thanks for any ideas.
--
Jim T