+ Reply to Thread
Results 1 to 3 of 3

Delete Autofiltered rows from multi-column Listbox

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Reading
    MS-Off Ver
    Excel 2010
    Posts
    2

    Delete Autofiltered rows from multi-column Listbox

    Hi,

    I am using an autofilter to display multiple columns of data from a worksheet in a userform listbox, which works well.
    I now want to select a row in the listbox and delete the content from the sheet. The problem I have is that the listbox "row" selected is being taken as an absolute, rather than referencing where the data resides on the worksheet.
    For example, selecting the first row on the listbox and deleting will delete row1 of the worksheet, regardless of whether it is part of the autofiltered data. What I need is a relationship between the autofiltered worksheet row number and the logical row numbers in the worksheet. The contents of the listbox is dynamic.

    Below is the "delete" code:

    Private Sub CommandButton12_Click()

    Dim I As Long

    With ListBox10
    For I = .ListCount - 1 To 0 Step -1
    If .Selected(I) Then
    .RemoveItem I
    Sheets("Sheet1").Rows(I + 2).EntireRow.Delete

    End If
    Next I

    End With
    End Sub

    Any help much appreciated

    Thanks

  2. #2
    Registered User
    Join Date
    03-26-2012
    Location
    India
    MS-Off Ver
    excel 2007
    Posts
    21

    Re: Delete Autofiltered rows from multi-column Listbox

    Hi can you share the sheet you are working on

  3. #3
    Registered User
    Join Date
    04-03-2012
    Location
    Reading
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Delete Autofiltered rows from multi-column Listbox

    Here is the workbook.
    If you run Userform2 from the excle VBA tool you can see it in action.

    Thanks
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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