+ Reply to Thread
Results 1 to 7 of 7

Find rows containing specific data and delete

  1. #1
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Find rows containing specific data and delete

    I have a large report that I pull each month listing which products we sold last month. There are certain products I don't want included in the report. Until I can have the report re-written, I'm looking for a macro or a function that will find all the rows that contain these product numbers in column M and delete the entire row. The product numbers I need to delete are always the same, but some months one or more of them might not be in the report if they weren't sold.

    In Summary:

    Find in column M the product numbers:
    c1000
    316140a
    316140
    316295a
    316295
    316311a
    316311
    316451a
    316451
    316450a
    316450
    316452a
    316452

    Delete those rows containing the product numbers above

    Thanks in advance for any help!


    ETA: I found a code (below) but when I highlight my row and run the macro, it deletes the first instance, but then I get an error saying "Object Required"

    Please Login or Register  to view this content.
    Last edited by kmlloyd; 01-06-2010 at 03:03 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find rows containing specific data and delete

    This should do it, it uses a loop, but only for the evaluation, for deleting it deletes all the found rows all at once which should be significantly more efficient.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-05-2010 at 06:31 PM. Reason: removed debug code
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Re: Find rows containing specific data and delete

    Hmmm I got an error:

    Object Variable or With block variable not set

    when I go into the code, it's highlighting this line:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find rows containing specific data and delete

    Must not have any data to delete. I suppose I always assumed that when you ran the macro, there would always be at least one match.

    Change that line to this so the macro won't bugger when you run it and there are no matches at all:
    Please Login or Register  to view this content.
    This should do it. If it still fails for some reason, I need to see the actual sheet/data you're trying this on.

  5. #5
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Re: Find rows containing specific data and delete

    Quote Originally Posted by JBeaucaire View Post
    Must not have any data to delete. I suppose I always assumed that when you ran the macro, there would always be at least one match.

    Change that line to this so the macro won't bugger when you run it and there are no matches at all:
    Please Login or Register  to view this content.
    This should do it. If it still fails for some reason, I need to see the actual sheet/data you're trying this on.
    Perfect! Actually - there was data to delete, but I realized that the data had "A" and not "a" and that's where it got caught...but this new line will help because I suppose there could be a time that there is no match...

    Thanks!!!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find rows containing specific data and delete

    You can add this to the top and it would make the whole macro non-case-sensitive.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Re: Find rows containing specific data and delete

    Quote Originally Posted by JBeaucaire View Post
    You can add this to the top and it would make the whole macro non-case-sensitive.

    Please Login or Register  to view this content.

    fabulous - thanks!!

+ 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