+ Reply to Thread
Results 1 to 8 of 8

Deleting all rows between two strings

  1. #1
    Registered User
    Join Date
    05-06-2010
    Location
    Derby
    MS-Off Ver
    Excel 2007
    Posts
    9

    Deleting all rows between two strings

    Hello,

    I’d be grateful for your help making a macro to delete all rows between two specified strings.

    It would look for two strings, always in column A: "Item Title" and any string beginning "Library" or "LIBRARY".

    It would delete all the rows between these cells (including the rows in which these two strings are found).

    Notes:
    - "Item Title" and "Library*" may appear multiple times in the worksheet, so multiple ranges may require deletion.
    - The number of rows between these two strings is unpredictable.
    - There may be up to 1,000 rows to check through.

    Example Workbook:
    The attachment shows a typical initial state. For clarity, I’ve highlighted in red two ranges that I’d like the macro to remove (they wouldn’t be highlighted in "real life"!).

    range_deletion_question.xlsx

    Thank you for any help you can offer.
    Matt

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Deleting all rows between two strings

    Please Login or Register  to view this content.
    Last edited by walruseggman; 12-03-2014 at 11:06 AM.

  3. #3
    Registered User
    Join Date
    05-06-2010
    Location
    Derby
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Deleting all rows between two strings

    Hello Walruseggman. Liking the Beatles reference.

    Thank you very much for offering a solution; unfortunately nothing seems to happen when I run it - not even an error.

    I've attached the workbook, now with the macro. You'll probably find it works fine and I'm probably being a moron...

    Attachment 362617

    Best wishes,

    Matt

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Deleting all rows between two strings

    Yeah, I probably should have looked at your example. I wasn't aware that the Library cells would have more text in them than just the word Library.

    Anyway, I've tweeked the code and it does delete all your red text cells in your original sheet (the link to the new one you posted doesn't seem to work.)

    Let me know how it goes.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-06-2010
    Location
    Derby
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Deleting all rows between two strings

    You're an absolute legend. Thank you very much, that works great!

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Deleting all rows between two strings

    Cool. Reputation would be appreciated (the * in the lower left of posts), and dont forget to mark this thread as SOLVED

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Deleting all rows between two strings

    Maybe:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-06-2010
    Location
    Derby
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Deleting all rows between two strings

    Hi John - that worked perfectly too. Thank you very much indeed for your time.

+ 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 strings from formulas
    By twt4757 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2013, 02:07 PM
  2. Replies: 2
    Last Post: 08-20-2013, 07:52 AM
  3. [SOLVED] Deleting part of a column without deleting whole rows.
    By dstrdOne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2013, 11:42 AM
  4. Macro help deleting rows with selected character strings
    By rliccion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2009, 01:45 PM
  5. deleting rows containing certain strings
    By pilch in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2008, 05:23 AM

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