Hello,
I have a workbook with Two Listbox.
I just want when the user click the item in Listbox1, it will move to Listbox2.
Appreciate your help.
I've attached the workbook.
Hello,
I have a workbook with Two Listbox.
I just want when the user click the item in Listbox1, it will move to Listbox2.
Appreciate your help.
I've attached the workbook.
Try this...
Private Sub ListBox1_Click() Dim i As Integer If ListBox1.ListIndex = -1 Then Exit Sub For i = ListBox1.ListCount - 1 To 0 Step -1 If ListBox1.Selected(i) = True Then ListBox2.AddItem ListBox1.List(i) End If Next i End Sub
Thanks moonsaga, but how can i remove the selected items from listbox1?
Here is another way.. found on thread in this forum.. http://www.excelforum.com/excel-prog...m-listbox.html
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim i As Long ListBox2.AddItem ListBox1.Value For i = 0 To ListBox1.ListCount - 1 If i > ListBox1.ListCount - 1 Then _ Exit Sub If ListBox1.Selected(i) = True Then _ ListBox1.RemoveItem (i) Next i End Sub Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim i As Long ListBox1.AddItem ListBox2.Value For i = 0 To ListBox2.ListCount - 1 If i > ListBox2.ListCount - 1 Then _ Exit Sub If ListBox2.Selected(i) = True Then _ ListBox2.RemoveItem (i) Next i End Sub
Try this code to replace the current ListBox1_Click
Private Sub ListBox1_Click() Dim RowToDelete As Long With ListBox1 ListBox2.AddItem .Value RowToDelete = .ListIndex .ListIndex = -1 .RemoveItem RowToDelete End With End Sub
Thanks All. Resolved!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks