+ Reply to Thread
Results 1 to 12 of 12

How to remove ALL rows that DO NOT have a match for certain word or number

  1. #1
    Registered User
    Join Date
    03-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2002
    Posts
    3

    How to remove ALL rows that DO NOT have a match for certain word or number

    Hello my name is Dave. Thank you for such a great forum.

    Here is my problem.

    I use Excel 2002 and have a file with 40,000 rows

    I want to search in column J for the word "sacked" and remove ALL rows that DO NOT have a match for that word. Any idea of a fast macro to do that?

    Thanks in advance. I hope I have explained what I am needing well.

    Dave

  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: How to remove ALL rows that DO NOT have a match for certain word or number

    Assuming row1 is your titles and data starts at row2... the AutoFilter is perfect for this. This macro will the AutoFilter on column J to hide rows that have the word "sacked", deletes all the rest all at once.

    Please Login or Register  to view this content.
    _________________
    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 Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    or ?

    Please Login or Register  to view this content.
    Last edited by snb; 03-18-2011 at 04:31 AM.



  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: How to remove ALL rows that DO NOT have a match for certain word or number

    SNB, you're basically making the same suggestion I did, except you've introduced the "special cells" method unnecessarily. With the limitation of 8500 "areas" in special cells, it should never be used on large data sets (40k rows) when a simple alternate method can be used that will avoid the built in limitation altogether.

    Also, your code simply ignores the fact that other prior Autofilters might break the code.

    Respectfully, offering the same technique with fewer lines of code isn't always necessary. And in this case is definitely not safer.
    Last edited by JBeaucaire; 03-18-2011 at 10:02 AM.

  5. #5
    Registered User
    Join Date
    03-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2002
    Posts
    3

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    JBeaucaire that worked awesome.

    OK next question.

    Same setup but now in row J, I want to look for the phrase:

    "for 10 yards"

    or greater

    meaning the it will keep ALL rows with: "for 10 yards" "for 11 yards" "for 12 yards" and on up to "for 100 yards"

    Hopefully I explained that right. You people are fantastic.

    Dave

  6. #6
    Registered User
    Join Date
    12-28-2009
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    2

    Thumbs up Re: How to remove ALL rows that DO NOT have a match for certain word or number

    I was just looking for something similar, except, I needed to keep the filter criteria.

    Many thanks

    Jeff

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

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    I hate "looping" code over and over to do the same evaluation, the AutoFilter makes that possible to skip, many times.

    Your original question was for a single "text string match" against a single column. Perfect for autofilter, one time, straight shot, done.

    Your new request is not so simple. Your mind views "for 10 yards"...."for 100 yards" as a simple step, but you have really added 90 new "strings". They're all different.

    So I can't really picture a way to NOT run the AutoFilter 90 separate times, which is fine to do, but deleting rows 90 times instead of all at once....what a chore.

    You said "row J" which doesn't mean anything. I presume you meant to change to another column, so I underlined the number you need to edit to match the column number you want to evaluate. I made it column K for now.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2002
    Posts
    3

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    I might have explained it wrong. In the 2nd question I no longer care about the word "sacked" as that task is done. What I am looking for now is to keep rows that have the phrase "for 10 yards" or greater all the way up to "for 100 yards" in column J.

    Sorry I if I did not explain it correctly. You are great for helping!

    Dave
    Last edited by shg; 03-18-2011 at 07:21 PM. Reason: deleted spurious quote

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

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    Did you try simply removing all that stuff relating to sacked?

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 03-18-2011 at 10:27 PM. Reason: Corrected type in filter syntax

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    or
    Please Login or Register  to view this content.

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

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    Sorry, SNB, I repeat my concern with applying SpecialCells to a dataset known to be 40k rows deep. Anyway...

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to remove ALL rows that DO NOT have a match for certain word or number

    I would echo JB's comment. If you're learning to code, adopt code you can read, understand, and learn from.
    Entia non sunt multiplicanda sine necessitate

+ 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