+ Reply to Thread
Results 1 to 13 of 13

delete rows not containing certain text

  1. #1
    Registered User
    Join Date
    04-17-2020
    Location
    Newcastle
    MS-Off Ver
    office 365
    Posts
    66

    delete rows not containing certain text

    Hi All,

    I need a macro to delete all rows which do NOT contain a certain string. The string i would like to specify in a message box, where uppercase or lowercase versions of that string in column G are found I would like the entire row deleted. I need to do this often hence the need for a macro and not filter.

    thanks

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,855

    Re: delete rows not containing certain text

    This macro assumes your data you are looking for is in Column G and data starts in row 2. It also assumes there is no difference between capitalized and non capitalized strings.

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: delete rows not containing certain text

    Hi Alan
    Maybe
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,855

    Re: delete rows not containing certain text

    @jolivanes

    Exactly!! I wrote aircode and did not test. Bad on me, but OP didn't supply sample data to test either.

    Alan

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: delete rows not containing certain text

    No problem Alan. 4 Eyes see more than 2.
    I hope you can do me the same favor sometime. (There probably will be lots of opportunities)

  6. #6
    Registered User
    Join Date
    04-17-2020
    Location
    Newcastle
    MS-Off Ver
    office 365
    Posts
    66

    Re: delete rows not containing certain text

    Thanks guys, both versions work on small spreasheets but when i run it on my spreadsheet which is huge (600k rows) it hangs. Also i should mention Column G doesnt just have the value i'm looking for, its part of the string so i assume that will take time as well. Any ideas how i should handle this?

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,855

    Re: delete rows not containing certain text

    Show us some sample data so we can provide a clear resolution. There may be alternatives, but without clear examples, I can offer no further explanation or resolution. See the yellow banner at the top of this page.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: delete rows not containing certain text


    Hi !

    Quote Originally Posted by garyb123 View Post
    so i assume that will take time as well.
    No as just operating manually with some Excel basics like any Excel beginner can do
    often needs no more than a minute so for casual need a VBA procedure is useless.
    And when a VBA procedure is really necessary so just reproducing this easy way …

    Attach a workbook in binary mode (.xlsb) with more than 10K rows - the more, the better - in order any helper can give it a try …

  9. #9
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,895

    Re: delete rows not containing certain text

    With the same assumptions as post #2, applying a filter and deleting visible rows seems pretty quick in my test with 600,000 rows of text data in columns A-Z

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: delete rows not containing certain text

    Don't know about 600K rows. All you can do is try on a copy of your workbook.
    Please Login or Register  to view this content.
    ByteMarks is faster. It looks to be very similar. Have your pick.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: delete rows not containing certain text


    A reminder : as clearing may be faster than deleting … The more non contiguous rows to delete, the slower …

  12. #12
    Registered User
    Join Date
    04-17-2020
    Location
    Newcastle
    MS-Off Ver
    office 365
    Posts
    66

    Re: delete rows not containing certain text

    Thanks jolivanes, that worked a treat.

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: delete rows not containing certain text

    Thanks for letting us know.
    Good Luck

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. delete rows not containing certain text
    By ewso in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-30-2017, 04:06 AM
  2. How to delete rows which contain a particular text
    By sumesh56 in forum Excel General
    Replies: 2
    Last Post: 10-06-2014, 10:39 AM
  3. Macro to keep rows that have certain text in one column, delete rows that do not.
    By mandalope in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2014, 02:35 PM
  4. How do I delete all rows containing a certain text string? / rows containg x, y. or z
    By pgalgiani in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-20-2012, 06:35 PM
  5. find text then delete two rows below it including row of found text
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-25-2011, 08:05 AM
  6. Delete rows with numeric values, leave rows with text
    By GSpline in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2005, 08:05 PM
  7. [SOLVED] delete empty rows between rows with text
    By Paulo Baptista in forum Excel General
    Replies: 2
    Last Post: 02-28-2005, 12:06 PM

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