Hi - I have a listbox, and a button that is supposed to transfer the (multiple) listbox selections into an excel spreadsheet. It used to work just fine, but I recently tried to use the feature and it's no longer functional. At this point, if a user selects multiple items from the list box and runs the macro, only ONE (the first) selected item gets transferred instead of all of them.
I'm stumped about this for a couple reasons: 1) I have not changed the script; 2) The macro still works for the first checked item but none of the others; and 3) Although the macro doesn't work for transferring all the checked items, it does work for unchecking/deselecting each item initially selected (leading me to believe that the for/next loop works at least partially - see code about halfway down).
Private Sub CommandButton1_Click()
Dim lItem As Long
Dim bCheck As Boolean
Application.ScreenUpdating = False
'Loop through all items in Listbox to see which is selected
For lItem = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(lItem) = True Then 'Selected
bCheck = True 'No message box needed to say "No items chosen"
'Transfer the selected item to the bottom of list in Column B
Me.Range("C2000").End(xlUp)(2, 1) = Me.ListBox1.List(lItem)
Me.ListBox1.Selected(lItem) = False 'Deselect Item
End If
Next lItem
If bCheck = False Then 'No selections
MsgBox "No items chosen"
End If
Application.ScreenUpdating = True
End Sub
Any suggestions are greatly appreciated!
Bookmarks