+ Reply to Thread
Results 1 to 10 of 10

Having an issue deleting rows based on certain text found in them...

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Having an issue deleting rows based on certain text found in them...

    Hey Guys,

    I'm having a little issue deleting entire rows when certain text is found in them, basically if there are two rows next to one another it only deletes one of the offending rows because the second row becomes the first row, I know how to fix it but am unsure how to code it.

    My current code is as follows:
    Please Login or Register  to view this content.
    It should be going from bottom to top to avoid this or putting them in a group and then deleting them all at once, could someone help me with this problem.

    Thanks in advance
    - Hyflex

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Having an issue deleting rows based on certain text found in them...

    Hi,

    I'd use an advanced Data Filter to filter the range in place. Then use the

    Please Login or Register  to view this content.
    syntax to delete them all.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Having an issue deleting rows based on certain text found in them...

    Hi Richard,

    For some reason filters seem to act up on my computers as I switch between 2003, 2007, 2010 and 2013 (different computers have different versions installed), I avoid filters at all costs because of this.

    Is there an easy alternative?

    Thanks
    - Hyflex

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Having an issue deleting rows based on certain text found in them...

    Hi

    I avoid looping macros wherever possible. They are inherently slow and less efficient. Filtering is the fastest and simplest way of doing this sort of stuff.

    May I respectfully suggest that you work out why filters are 'playing up'. I've used Filtering in all versions of Excel since about 1992 and never had any problems. I'd go so far as to say this functionality is the most robust of all.

    Can you expand on the apparent difficulties you have with filtering. Being able to use them will significantly enhance your Excel experience and efficiency.

  5. #5
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Having an issue deleting rows based on certain text found in them...

    Hey Richard,

    Well yeah, I agree they are slow but my data is only 5,000 rows so it's pretty much nothing so it wouldn't be a problem.

    The issue is it crashes excel, debugs and sometimes just doesnt do anything.

  6. #6
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Having an issue deleting rows based on certain text found in them...

    I had a go at doing it via autofilter and ran into a problem where if there are no rows it errors out as it can't find anything...

    Please Login or Register  to view this content.
    Note: Column 1 and 3 have data in them which I don't want touched so I changed it to A4 instead of A1

  7. #7
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Having an issue deleting rows based on certain text found in them...

    Quote Originally Posted by Richard Buttrey View Post
    ...
    I avoid looping macros wherever possible. They are inherently slow and less efficient.
    ...
    Is this really right?

    Suppose you have numbers RandBetween(1, 1million) listed in Range "A&1" to "A&1million".

    Removing any duplicated values should take less than one second using a decent looping macro.

    Using any filters, or advanced filter, or RemoveDuplicates (if it works) would take (quite a lot) significantly longer. Could you show otherwise?

    I'm just concerned about the implied generality in your statement, which may not be helpful to a lot of users, in this thread or elsewhere.
    Last edited by kalak; 06-04-2014 at 12:25 AM.

  8. #8
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Having an issue deleting rows based on certain text found in them...

    Quote Originally Posted by Hyflex View Post
    I had a go at doing it via autofilter and ran into a problem where if there are no rows it errors out as it can't find anything...

    Please Login or Register  to view this content.
    Note: Column 1 and 3 have data in them which I don't want touched so I changed it to A4 instead of A1
    I can't seem to work out how to detect if it's caught any results.

    I did a backwards step loop as seen below:

    Please Login or Register  to view this content.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Having an issue deleting rows based on certain text found in them...

    Hi,

    The scenario you paint using Rand presumably means that calculations are taking place as each row is deleted by the system via the filter technique - or at least I'm assuming this - I've not tested it yet.

    But assuming you are right I regard this as a very special case since most times I add this advice, and it's very often, Rand is not involved and clearly if it's not using filtering rather than looping is by far the quickest and efficient method I know.

    I'll check in due course whether what you are saying is in fact the case and assuming it is I'll caveat future similar responses accordingly. Thanks for flagging it up.

  10. #10
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Having an issue deleting rows based on certain text found in them...

    Rand was just an easy and quick way of generating a large sample set.

    Can get large sample sets other ways.

    Point being made was that general statements such as "... looping macros ... are inherently slow and less efficient." (as compared with filters) are in many cases just not correct, and thus may be unhelpful to contributors seeking help.

    Following code was used to generate, as illustrative counter-example, a large set of numbers
    Please Login or Register  to view this content.
    If aim is to find the unique values from the resulting dataset, like Excel's RemoveDuplicates tries to do, then filtering is inherently slow and inefficient.

+ 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. Deleting rows based on Date and Text
    By bobert5ama in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2013, 12:29 AM
  2. Macro - deleting rows if no image found on server
    By DeanR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2013, 11:02 AM
  3. Macro to copy and paste rows based on "text" found in Column A
    By balston2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-09-2013, 12:35 PM
  4. Deleting rows based upon partial cell text
    By mjwillyone in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2008, 10:29 PM
  5. Deleting Rows - a new issue
    By iain_clark in forum Excel General
    Replies: 8
    Last Post: 03-09-2007, 01:34 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