Multiple Listbox Transfer help please

Soulfien

New member
Joined
Oct 17, 2016
Messages
8
Reaction score
0
Points
0
I'm using a Multi Listbox Userform.

It contains two listboxes and an "Add" and "Remove" Button to populate listbox2 (Destination) two with the list from listbox1 (Origin). (I cannot yet post links or images)

I've added a transfer button, but I've no way to have it transfer all items from Listbox2 into the worksheet unless I first "select" all items in listbox2. I would like Listbox2's entire contents be transferred to the worksheet regardless of whether or not they've been "selected".

After all, the reason I'm using two Listboxes is to eliminate the need to "select" the items to be transferred. Thanks for all the help that's gotten me this far! You all are awesome!

Jeremie
 
Here's the transfer button that I added. It only transfers selected items in Listbox2. It disregards all non-highlighted items. For simplicity's sake, I kept all of the code identical to the tutorial I linked


Private Sub cmdTransfer_Click()
Dim lItem As Long, lRows As Long, lCols As Long
Dim bSelected As Boolean
Dim lColLoop As Long, lTransferRow As Long

'Pass row & column count to variables
'Less 1 as "Count" starts at zero
lRows = ListBox2.ListCount - 1
lCols = ListBox2.ColumnCount - 1

'Ensure they have at least 1 row selected
For lItem = 0 To lRows
'At least 1 row selected
If ListBox2.Selected(lItem) = True Then
'Boolean flag
bSelected = True
'Exit for loop
Exit For
End If
Next

'At least 1 row selected
If bSelected = True Then
With Sheet1.Range("D1", Sheet1.Cells(lRows + 1, 4 + lCols)) 'Transfer to range
.Cells.Clear 'Clear transfer range
For lItem = 0 To lRows
If ListBox2.Selected(lItem) = True Then 'Row selected
'Increment variable for row transfer range
lTransferRow = lTransferRow + 1
'Loop through columns of selected row
For lColLoop = 0 To lCols
'Transfer selected row to relevant row of transfer range
.Cells(lTransferRow, lColLoop + 1) = ListBox2.List(lItem, lColLoop)
'Uncheck selected row
' ListBox1.Selected(lItem) = False
Next lColLoop
End If
Next
End With
'Unload Me
Else ' NO listbox row chosen
MsgBox "Nothing chosen", vbCritical
End If
End Sub
 
Resolved.

By setting checkbox2 to True when Transfer is pressed, it all works out. Thanks for the replies :)
 
Thanks for letting us know about your cross posting.

Do you have the decency to give credit where credit is due?
 
Last edited:
cooper645 mikeerickson Redbeard MickG Kenneth Hobson

Decency? Are you for real? I can't tell if you're just having a bad day or if you're just always this rude, but sure. I'll ignore the fact that you're challenging my decency and list the names of those that have helped me with my Excel project.

cooper645, mikeerickson, Redbeard, MickG, and Kenneth Hobson

These are all the names that have replied and helped work towards a solution. As for my cross posting, it's actually quite a common practice. I suggest you try it sometime. It's effective and the only time that it's rude is if you don't stop by and let all the places know once a solution is reached.

I apologize if I misinterpreted your post, but it reads quite rudely.
 
Resolved.... didn't exactly give credit.

As for my cross posting, it's actually quite a common practice. I suggest you try it sometime. It's effective and the only time that it's rude is if you don't stop by and let all the places know once a solution is reached.
Did you read the rules at any of the sites?

#13 here has a link to this here on this site. You should read it for an understanding. Cross posting isn't forbidden, but it's to be done in the appropriate manner.
 
Back
Top