reasem
New Member
- Joined
- Nov 15, 2019
- Messages
- 38
I have a code that moves data from one ListBox to another using 4 buttons, but it only moves the data in the first column of the listbox. I'm looking for it to transfer the whole row in ListBox3 to ListBox4 and vice versa. I think my issue has to do with the AddItem and RemoveItem codes as they must only transfer one cell at a time.
Here's the code
Here's the code
VBA Code:
Private Sub BTN_moveAllLeft_Click()
'Add the items to the other ListBox
For i = 0 To ListBox4.ListCount - 1
ListBox3.AddItem ListBox4.List(i)
Next i
'Remove the items from the ListBox
ListBox4.Clear
'Remove items filled with RowSource
'ListBox2.RowSource=""
End Sub
Private Sub BTN_moveAllRight_Click()
'Add items to the other ListBox
For i = 0 To ListBox3.ListCount - 1
ListBox4.AddItem ListBox3.List(i)
Next i
'Remove the items from the ListBox
ListBox3.Clear
'Remove items filled with RowSource
'ListBox1.RowSource=""
End Sub
Private Sub BTN_MoveSelectedLeft_Click()
'Loop through the items
For itemIndex = ListBox4.ListCount - 1 To 0 Step -1
'Check if an item was selected.
If ListBox4.Selected(itemIndex) Then
'Move selected item to the right.
ListBox3.AddItem ListBox4.List(itemIndex)
'Remove selected item from the left.
ListBox4.RemoveItem itemIndex
End If
Next itemIndex
End Sub
Private Sub BTN_MoveSelectedRight_Click()
'Loop through the items
For itemIndex = ListBox3.ListCount - 1 To 0 Step -1
'Check if an item was selected.
If ListBox3.Selected(itemIndex) Then
'Move selected item to the right.
ListBox4.AddItem ListBox3.List(itemIndex)
'Remove selected item from the left.
ListBox3.RemoveItem itemIndex
End If
Next itemIndex
End Sub
Private Sub UserForm_Activate()
Me.ListBox3.Clear
Me.ListBox4.Clear
ListBox3.ColumnCount = 5
ListBox4.ColumnCount = 5
Me.ListBox3.List = Worksheets("Sheet3").Range("Household").Value
Me.ListBox3.MultiSelect = fmMultiSelectMulti
Me.ListBox4.MultiSelect = fmMultiSelectMulti
End Sub