Delete & Unfilter

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

It does work when I try it.

But even simpler, you can replace those two lines with

Cells.EntireRow.Hidden = False
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

Does the code delete any two rows that you select from the list box and unhide the hidden rows?
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

The line of code from my previous reply will unhide all rows. It doesn't delete any rows, you already have working code for that.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

The two codes you have provided does unhide after deleting the selected row. My intention is to delete multiple rows as from beginning. The cord works well if a single row is selected.

My intention is to select multiple rows when the listbox gets filtered and among them to select couple of rows. Delete them and unhide the rows.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

Sorry, I don't understand your description.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

What I meant is that addition of the line

Cells.EntireRow.Hidden = False

does delete the selected row from the list box and unhide the hidden row. This works very well if a single row is selected from the list box.

But if I select multiple rows from the list box, the code does not seem to delete and unhide all the rows that I select from the list box.

I've set the Multiselect property of the list box to 1-fmMultiSelectMulti so that I could select multiple rows from the listbox.

But still I cannot make it work.

I hope I have made my question clear.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

That line of code does not, repeat NOT delete any rows.

The code in Post=21229 earlier in this thread should correctly delete rows if multiple items have been selected in the list box.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

Yes Hans the code in Post=21229 does delete the rows, if multiple items have been selected in the list box. but it does not unhide the hidden rows.

So I had asked how to unhide the rows after deleting the rows and the final line you had given me was the line at Post=21266.

After the addition of the line from Post=21266 the code does delete only one row or does not delete either row but does unhide the hidden rows as you told.

What I'm trying to do is both. To delete the multi selected rows and unhide the hidden rows.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

Could you post the latest version of the code or the workbook?
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

I've not made any changes to the workbook. It is as same as that of at Post=21228.

But the code is as follows,

Code: Select all

Private Sub CommandButton_Remove_Click()
  Dim i As Long
  For i = Me.ListBox2.ListCount - 1 To 0 Step -1
    If Me.ListBox2.Selected(i) Then
      With Range("Data").SpecialCells(xlCellTypeVisible)
        .Rows(i + 1).Delete
      End With
    End If
  Next i
  Cells.EntireRow.Hidden = False
  FilterList
End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete & Unfilter

Post by HansV »

It turned out to be mor complicated than I thought. I won't bother you with the reasons.

I have added a hidden column to the listbox that lists the row numbers of the items. This hidden column is used to determine which rows should be deleted.

See the attached version.
Filter.xlsm
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Delete & Unfilter

Post by adam »

Thanks for the help Hans. The code now works fine. And I do really appreciate for the help you had given.
Meanwhile, congrats as Netherlands are through to semi-finals of 2010.
Best Regards,
Adam