Removing an Item from a list box

  • Hi,


    I'm going round in circles here! How do I remove an item from a list box, when it is selected in the list and a "remove" button is clicked on?



    Many Thanks,


    Jon

  • Re: Removing an Item from a list box


    Hi nojy


    Code
    ListIndex = 1  'First Item is list
            MyListBox.RemoveItem (MyListBox.ListIndex)


    hope this helps


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Removing an Item from a list box


    Hi Jon,


    Something like this would do it. Assuming non multi-select listbox.


    Code
    Private Sub CommandButton1_Click()
        If ListBox1.ListIndex >= 0 Then
            ListBox1.RemoveItem ListBox1.ListIndex
        End If
    End Sub

    [h4]Cheers
    Andy
    [/h4]

  • Re: Removing an Item from a list box


    nojy,


    This can present some challenges especially if you allow multiple items to be selected. Due to lack of information I'm going to assume that the list box is on a userform or it's an ActiveX type listbox on a worksheet.



    If you allow multiple items to be selected you must remove the last selected item first and loop to the beginning.


    Code
    For intCount = ListBoxNameHere.ListCount - 1 to 0 step -1
         if ListBoxNameHere.Selected(intCount) then ListBoxNameHere.RemoveItem(intCount)
    next intCount


    See if this works for you.

  • Re: Removing an Item from a list box


    To remove an item from a listbox, you can 1) remove the item(s) from the actual list on the worksheet, as prescribed by the Input Range that you created, or 2) modify the Input Range field such that the cell reference(s) that you wish to remove are deleted. Not sure what you mean by a "remove" button. Am I missing something, friend?


    Bubbis Thedog

    :silverha:

  • Re: Removing an Item from a list box


    Thanks guys for the swift replies i've used bits from all answers and got a perfect working remove button in my Form to remove items from a list.


    Thanks again!


    Jon

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!