+ Reply to Thread
Results 1 to 14 of 14

Delete / Keep rows containing specific text.

  1. #1
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Delete / Keep rows containing specific text.

    Hello

    I need some help to remove/keep rows from a large spreadsheet. I think the easiest way would be to specify the text in the row I want to keep.
    The text which requires sorting is in one column A: and looks like this -

    ARM0009
    ARM0041
    BOR0024
    BOR0035
    CEN0029
    CHS0003

    for the above I would like to retain rows which contain BOR and CEN and delete all the others.

    I have tried numerous macros but being new to it I'm struggling to get anything to work.

    Any help would be much appreciated.

    Thanks
    Last edited by fluteloop; 12-05-2011 at 08:35 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Delete / Keep rows containing specific text.

    there are several ways of doing this, depends on what all your data looks like.you can simply filter on does not begin with bor or cen and delete the visible rows
    or if there are more conditions an advanced filter or even a function to identify which rows to discard /keep
    or since this is the programming sub forum perhaps some vba to automate the whole thing but thats probably overkill lol
    Last edited by martindwilson; 12-04-2011 at 06:15 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Delete / Keep rows containing specific text.

    Hi Martin thanks for the response.
    The filter seems a good idea although I'm dealing with this data daily an to have an automated process would be excellent.
    I did have a go with a few scripts already on here but failed to have any luck.

    Some help on how to get the script going would be great or any other suggestions welcome.

    Thanks

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete / Keep rows containing specific text.

    try so
    Please Login or Register  to view this content.
    It is assumed that A1 is the column header.
    Last edited by nilem; 12-05-2011 at 06:36 AM. Reason: add code tags

  5. #5
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Delete / Keep rows containing specific text.

    Thanks Nilem that worked great.
    How do I go about adding in more arguments to the filter command?
    I tried expanding on BOR and CEN with 6 others (TYR, TYN, LOT) following the same command but it gave an error of Wrong Number of Arguments or Invalid Property Assignment.

    Thanks

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete / Keep rows containing specific text.

    Try different options
    Please Login or Register  to view this content.
    oops these options are not working correctly
    Last edited by nilem; 12-05-2011 at 07:02 AM. Reason: oops

  7. #7
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Delete / Keep rows containing specific text.

    Thanks Nilem. I was having problems with it as well.

    I have attached a simple test file which will give you an idea of what I'm trying to achieve.

    Thanks

    Gary
    Last edited by fluteloop; 12-05-2011 at 08:28 AM.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete / Keep rows containing specific text.

    Hi, Gary. Let's try without a filter.
    Please Login or Register  to view this content.

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

    Re: Delete / Keep rows containing specific text.

    Please Login or Register  to view this content.
    Last edited by snb; 12-05-2011 at 08:13 AM.



  10. #10
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Delete / Keep rows containing specific text.

    Thanks Nilem, Got it sorted!! I was looking at the wrong line!!!

    This is a great help and very much appreciated.

    Regards
    Last edited by fluteloop; 12-05-2011 at 08:27 AM.

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete / Keep rows containing specific text.

    highlighting - it was just for testing
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    12-04-2011
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Delete / Keep rows containing specific text.

    Thanks, Took me a bit of time to notice!!!

    Thanks again.

  13. #13
    Registered User
    Join Date
    09-30-2014
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    1

    Re: Delete / Keep rows containing specific text.

    I know this thread is old but I have a similar problem.

    I used the macros provided here to sort some rows successfully but I need a certain row and the following one. My data looks somewhat like this:

    BRBRBRBR
    1234

    BRBRBRBR
    4567

    BRBRBRBR
    7890

    and I need every row with BR plus the one that comes after it.

    Thanks in advance for any kind of assistance.

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,642

    Re: Delete / Keep rows containing specific text.

    pedrohcost,
    I know this thread is old but ... (I don't care...)
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

+ 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