+ Reply to Thread
Results 1 to 6 of 6

when removing filter all data disappears

  1. #1
    Forum Contributor rinser's Avatar
    Join Date
    02-27-2009
    Location
    Bucharest
    MS-Off Ver
    MS Office 2013
    Posts
    103

    when removing filter all data disappears

    Hi All,

    I have a filter in my code that is supposed to filter data by a certain criteria, delete the filtered results and afterwards eliminate filter so that remaining rows would be seen by the next module.
    The thing is it does filter correctly, but then if there is no data to delete (no data meets filter criteria), after removing the filter there is actually no data at all - it deletes the rows hidden by filter, it seems. If there is data that meets criteria and should be deleted then it deletes it and after removing the filter the data is ok. The problem arises when there is nothing to delete, it just deletes the hidden (by filter) rows.
    Here is the code (the filter part is in bold):
    Please Login or Register  to view this content.
    This is a sample of the data:
    Sample sorting.xls

    Please advise me as to what is wrong with this code or how can it be improved. Any ideas appreciated.
    Last edited by rinser; 12-17-2009 at 07:40 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    re: when removing filter all data disappears

    See if this works.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor rinser's Avatar
    Join Date
    02-27-2009
    Location
    Bucharest
    MS-Off Ver
    MS Office 2013
    Posts
    103

    Re: when removing filter all data disappears

    Hi Stephen,

    Thank you for fast response. I have tried the code and it seems to be doing the job. I will test it more tomorrow and get back.

    Cheers.

  4. #4
    Forum Contributor rinser's Avatar
    Join Date
    02-27-2009
    Location
    Bucharest
    MS-Off Ver
    MS Office 2013
    Posts
    103

    Re: when removing filter all data disappears

    Hi Stephen,

    I made some testing and it seems to work. Sometimes (when there are only a few rows) I got an error, after removing On Error GoTo 0 it seems to work fine. Is it safe to remove the On Error GoTo 0?

    Cheers.

  5. #5
    Forum Contributor rinser's Avatar
    Join Date
    02-27-2009
    Location
    Bucharest
    MS-Off Ver
    MS Office 2013
    Posts
    103

    Re: when removing filter all data disappears

    Stephen,

    Your solution works so I am closing the thread.

    Thanks for help!

  6. #6
    Registered User
    Join Date
    09-19-2009
    Location
    LONDON
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: when removing filter all data disappears

    I have similar issue
    whereby I am trying to delete filtered rows

    if the filters leave rows of data, it deletes them without any problem
    but the issue occurs when there was no results being returned from the filters, so effectively, just the heading row is visible

    and my vba code throws up an error and highlight my code in yellow.


    With .AutoFilter.Range
    On Error Resume Next
    Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    If Not rData Is Nothing Then
    rData.Delete shift:=xlUp
    End If
    End With
    .AutoFilterMode = False

    so is this part of the code gets around the error?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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