Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Delete only selected item from the listbox and listbox populating source.

  1. #1
    Board Regular
    Join Date
    Sep 2009
    Posts
    179
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Delete only selected item from the listbox and listbox populating source.

    Hi All,

    I have the below code which deletes all items from a listbox and my excel sheet which is the source for populating that listbox. I am using a option button style for my listbox and the selection style as single .i.e. you can select only one item at one go in the lisbox. I want my macro to delete the selected item from my worksheet .i.e. it's entire row so that it doesn't reflect in my lisbox any more. Below is my code :

    Code:
    Private Sub CommandButton2_Click()
     'REMOVE SELECTION
     
      Dim I As Long
     
        With ListBox1
          For I = .ListCount - 1 To 0 Step -1
           If .Selected(I) Then
               .RemoveItem I
               Sheets("URL List").Rows(I + 2).EntireRow.Delete
               
            End If
          Next I
        
    End With
    
    End Sub
    Thanks a lot for your help in advance.

  2. #2
    Board Regular sunnyland's Avatar
    Join Date
    Jan 2006
    Location
    Southport, Queensland, Australia
    Posts
    909
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Delete only selected item from the listbox and listbox populating source.

    'supposing sheet18 is the sheet with row to delete
    ' you cannot remove individual item in a linked list
    'so you will have to refresh the listbox
    'by reapplying the listfillrange

    Private Sub CommandButton1_Click()
    Dim indexi As Long
    indexi = ListBox1.ListIndex + 1
    If indexi <> -1 Then
    Sheet18.Rows(indexi).EntireRow.Delete
    ListBox1.ListFillRange = "a:a"
    End If
    End Sub
    Regards
    Francoise
    Women in 'Programming'
    Using Excel 2013 and Excel 365 - Standard Edition, Windows 10 Home Edition

  3. #3
    Board Regular
    Join Date
    Sep 2009
    Posts
    179
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Delete only selected item from the listbox and listbox populating source.

    Hi,

    Thanks a lot for your reply, It's working fine now.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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