+ Reply to Thread
Results 1 to 6 of 6

Delete rows NOT containing 1 of multiple strings in a column

  1. #1
    Registered User
    Join Date
    07-22-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2000
    Posts
    7

    Smile Delete rows NOT containing 1 of multiple strings in a column

    I have a table of action items that are still open, and Amy Bob, and Charlie are on my team.

    When I run a report, the table shows the current asignee in column N. I need a macro that sorts according to column N and deletes everybody except Amy, Bob and Charlie.

    Here's a shortened version of the table:

    Item#-Info---Asignee
    1-------info1--David
    2-------info2--Bob
    3-------info3--Amy
    4-------info4--Charlie
    5-------info5--Greg


    My goal:

    Item #-Info---Asignee
    3-------info3--Amy
    2-------info2--Bob
    4-------info4--Charlie

    Thanks!
    Last edited by jarochnrol; 07-25-2011 at 10:03 AM. Reason: solved

  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: Delete rows NOT containing 1 of multiple strings in a column

    1) In an empty column, enter a "key" formula to make this easy, starting in row2, then copied down:

    =OR(ISNUMBER(SEARCH($N2, {"Amy","Bob","Charlie"})))

    2) Turn on the AutoFilter then do a filter on that column for FALSE

    3) Delete all visible rows

    4) Turn off the Autofilter and clear the helper column of the formulas you added.

    Done.


    You can turn on the macro-recorder to turn that into a macro pretty easily, edit the resulting macro to add the formula in cells going down far enough to always cover the range of data you deal with typically, 500-1000 rows, perhaps.
    _________________
    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
    Registered User
    Join Date
    07-22-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2000
    Posts
    7

    Re: Delete rows NOT containing 1 of multiple strings in a column

    Great idea! I tried it and it worked well, except some tasks are left blank and have no asignees. Excel recognizes both the team members as well as the blanks as "true". How should I avoid this?

  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: Delete rows NOT containing 1 of multiple strings in a column

    Avoid how? What's supposed to happen with blank rows?

    If you want them deleted, too, then maybe this:

    =AND(N2<>"",OR(ISNUMBER(SEARCH(N2, {"Amy","Bob","Charlie"}))))

  5. #5
    Registered User
    Join Date
    07-22-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2000
    Posts
    7

    Re: Delete rows NOT containing 1 of multiple strings in a column

    Works perfect. Thanks a million!

  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: Delete rows NOT containing 1 of multiple strings in a column

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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