+ Reply to Thread
Results 1 to 3 of 3

list box script problems

Hybrid View

JChandler22 list box script problems 08-11-2008, 09:49 AM
royUK Make sure the ListBox's... 08-11-2008, 10:00 AM
JChandler22 Thanks - yes, it is still set... 08-11-2008, 10:08 AM
  1. #1
    Forum Contributor
    Join Date
    06-25-2007
    Posts
    166

    list box script problems

    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!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Make sure the ListBox's MultiSelect property is still set to Multi
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    06-25-2007
    Posts
    166
    Thanks - yes, it is still set that way. I have no problem selecting multiple items. They just don't all transfer.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1