+ Reply to Thread
Results 1 to 8 of 8

Delete Filtered Data

  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Delete Filtered Data

    I'm trying to have a macro filter a range then delete the results if there are any. I have successfully created the code to filter the range, but I am unable to correctly delete the results. I'm trying to delete only the visible cells in that range, but the macro for some reason seems to be deleting the entire row even though i'm not telling it too. What's wrong??

    Note: I posted this here a few days ago, with no luck: http://www.mrexcel.com/forum/showthread.php?t=454229

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Filtered Data

    Hello erock24,

    In your code you are extending the range to the bottom of the worksheet by using Rows.Count. Because the SpecialCells property has a limit of 8192 entires, you will need to limit the range to the last entry in the search range. Once this limit is exceeded, things get weird.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Delete Filtered Data

    Leith,

    Thank you for the reply. I edited the code to only go to the bottom of the filtered data. I get the same result. The code seems to be deleting the entire row, when I only want cells within my designated range to be deleted. Is this possible or does the code always default to entire rows in filter mode??

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Filtered Data

    Hello erock24,

    Can you post your workbook for review?

  5. #5
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Delete Filtered Data

    Sorry for the late response....attached is a sample with the filter code. The filtering works great. The code will filter the blue range 1st, then yellow, then green. It will not find anything in blue or yellow, but it will in green. But then the code doesn't work right. Instead of deleting just the green filtered range, it seems to delete entire rows.
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Filtered Data

    Hello erock24,

    As I understand your code, it is supposed to delete only the rows within each group if there is a zero in the fifth column. If that is correct then this macro will do that.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Delete Filtered Data

    Thank you for your reply. I already have similar code that loops through every cell stepping backwards through the ranges checking for 0 and deleting. The code works fine as does yours, but I was looking for something faster. In the real file the ranges are many thousands of rows and the code takes forever. That's why i thought the autofilter would be better. However, if looping is the only way then so be it.

    Thank you for your time and help.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Filtered Data

    Hello erock24,

    The drawback with filtering is it effects the entire row. You need to effect change only on specific columns and looping is the only way to accomplish that.

+ 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