Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Remove Listbox Item

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remove Listbox Item

    I have a list box and I input data into it.
    I have a delete button that removes items from the list box

    I am trying to tell it not to remove anything and display a msgbox when nothing is selected from the list box. But then if something is selected delete that one and only that one.


    HELP!!!!!

  • #2
    Re: Remove Item Listbox

    What kind of listbox are you using ( Forms or Control Toolbox )?

    If you're using the "Forms" type then you are making a list on a worksheet so simply remove the item from the list.

    If you're using the "Control Toolbox" type then you are using "AddItem" to input new items into a list box. So you can use "RemoveItem" along with the index of the selected item to remove a selected item.
    Regards,
    Barry

    My Favorite New Thing:
    Dynamic Named Ranges



    The alternative for
    "Press Any Key To Continue."

    and we all have one we'd like to use it on

    1. Cross Posting Etiquette
    2. Are You Here To Learn: What Have You Tried?
    3. Your Best Resource to begin learning VBA: RECORD A MACRO . . . Then Study It!

    Comment


    • #3
      Re: Remove Item Listbox

      I got it

      Code:
      Private Sub CommandButton2_Click()
      
      If UserForm8.ListBox1.Value = ListBox1 Then
          UserForm8.ListBox1.RemoveItem (UserForm8.ListBox1.ListIndex)
          UserForm8.TextBox6.Locked = False
      Else
      MsgBox "Please select a name to be Removed from this list", vbOKOnly + vbCritical, "ERROR"
      End If
          If UserForm8.ListBox1.ListCount = 0 Then
              UserForm8.ListBox1.Visible = False
              UserForm8.CommandButton2.Visible = False
          End If
      
      End Sub
      Last edited by Dave Hawley; July 20th, 2007, 12:35.

      Comment


      • #4
        Re: Remove Item Listbox

        I got it

        Code:
        Private Sub CommandButton2_Click()
        
        If UserForm8.ListBox1.Value = ListBox1 Then
            UserForm8.ListBox1.RemoveItem (UserForm8.ListBox1.ListIndex)
            UserForm8.TextBox6.Locked = False
        Else
        MsgBox "Please select a name to be Removed from this list", vbOKOnly + vbCritical, "ERROR"
        End If
            If UserForm8.ListBox1.ListCount = 0 Then
                UserForm8.ListBox1.Visible = False
                UserForm8.CommandButton2.Visible = False
            End If
        
        End Sub
        Last edited by Dave Hawley; July 20th, 2007, 12:35.

        Comment

        Trending

        Collapse

        There are no results that meet this criteria.

        Working...
        X