+ Reply to Thread
Results 1 to 3 of 3

Delete Rows If value is found

  1. #1
    Forum Contributor
    Join Date
    04-23-2007
    Location
    Texas
    Posts
    417

    Delete Rows If value is found

    I want to delete all rows where "name" is found in Range B:B

    So I'm using this and it only does like 5 or 6 rows then stops... I don't know why!
    Please Login or Register  to view this content.
    What am I screwing up?
    Last edited by Tortus; 02-15-2013 at 01:19 PM.

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Delete Rows If value is found

    When you delete the row, Excel loses track of where it is:
    If you delete row 4, excel moves the rows up so row 5 becomes row 4, but row 4 has already been through your loop, so Excel moves on to row 5 (which was 6). You can test this by adding:
    Please Login or Register  to view this content.
    One approach is to count backwards from
    Please Login or Register  to view this content.
    e.g.:
    Please Login or Register  to view this content.
    (in case it isn't obvious - this works because if you choose to delete a row, the rows above, and row numbering, are unaffected)
    Another (better) approach would be to add an autofilter to the range in question, filter for "name", delete all rows from beneath the header down then remove autofilter. Record a macro to get the syntax.
    Last edited by Cheeky Charlie; 02-15-2013 at 01:12 PM. Reason: code tags, why counting backwards works
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    Forum Contributor
    Join Date
    04-23-2007
    Location
    Texas
    Posts
    417

    Re: Delete Rows If value is found

    Ok, thank you. I'll record filtering for name and delete rows. Didn't think about doing 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