Results 1 to 5 of 5

Help with Add/Remove Items from One List Box to Another

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Help with Add/Remove Items from One List Box to Another

    Hello all,

    I am having trouble with some code to populate one User Form list box based on the values in another. The user has a list of available colors on the left and uses command buttons to either

    1) Add All
    2) Add Selected
    3) Remove Selected
    4) Remove All

    The Add All and Remove All functions are working but the Add/Removed selected is not.

    My code for Add Selected:
    Private Sub CmdBtn_AddColor_Click()
    '
    'Source: Move user selected values from list box 1 to list box 2: https://analysistabs.com/excel-vba/listbox-adding-clearing-items-multiple-selection/
    '
    
        Dim iCnt As Integer
        
        For iCnt = 0 To Me.LstBx_ColorsSelected.ListCount - 1
        If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
            Me.LstBx_ColorsAvailable.AddItem Me.LstBx_ColorsSelected.List(iCnt)
            End If
        Next
        For iCnt = Me.LstBx_ColorsSelected.ListCount - 1 To 0 Step -1
        If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
            Me.LstBx_ColorsSelected.RemoveItem iCnt
            End If
        Next
            
    End Sub
    My code for Remove Selected, this function simply needs to remove the selected items from the list box, it does not need to repopulate them back to the other list box.

    Private Sub CmdBtn_RemoveColor_Click()
    '
    'Source: Move user selected values from list box 1 to list box 2: https://analysistabs.com/excel-vba/listbox-adding-clearing-items-multiple-selection/
    '
    
        Dim iCnt As Integer
        
        For iCnt = 0 To Me.LstBx_ColorsSelected.ListCount - 1
        If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
            Me.LstBx_ColorsSelected.RemoveItem
        End If
            
        
    End Sub
    A copy of my project is attached. I have not yet written code for the other functions of the User Form.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Remove items from dropdown list when item value = 0
    By technolog in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-21-2017, 09:57 AM
  2. Best way to remove items from list
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2014, 12:32 PM
  3. Replies: 1
    Last Post: 09-14-2013, 04:55 AM
  4. Replies: 2
    Last Post: 08-23-2011, 08:55 PM
  5. Remove matching items from a workbook based on a master list
    By Apel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2009, 08:20 PM
  6. cleaning up my list - remove items in the list
    By tmssj2000 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-06-2009, 02:00 AM
  7. remove items from list box (sorry it`s a bit long)
    By bahadirakcan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2006, 08:11 AM

Tags for this Thread

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