+ Reply to Thread
Results 1 to 8 of 8

Search for matching text, then delete rows above it.

  1. #1
    Registered User
    Join Date
    07-08-2009
    Location
    PA, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Question Search for matching text, then delete rows above it.

    Here is what Im trying to do: I have a VERY large excel file that has groups of 4 cells, a blank, then another 4, repeating. Kinda like the following:

    ExampleCell1
    ExampleCell2
    ExampleCell3
    UID = example

    ExampleCell1
    ExampleCell2
    ExampleCell3

    ExampleCell1
    ExampleCell2
    ExampleCell3
    UID = example


    That pattern continues for about 3000 lines. However, if you noticed, some of the "groups" dont have the 4th line "UID = example".

    Here is what Im trying to do. I want excel to search for the cells with "UID" and DELETE it plus the 3 rows above. So that only the "groups" without the UID remain.

    Now Im thinking this may be impossible, but I've seen some crazy things done with excel macros and was really hoping someone can help me out. Otherwise Im doing this manually for 3000+ lines of text.
    Any suggestions are GREATLY appreciated!!!!!!!
    Last edited by mainer188; 07-09-2009 at 05:28 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Looking for VB help.

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then amend your thread title accordingly.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Search for matching text, then delete rows above it.

    Thank you.

    Try this:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Unhappy Re: Search for matching text, then delete rows above it.

    I'm sure I posted a solution to this earlier, but it seems to have been deleted along with the sample workbook that had been uploaded previously?
    Last edited by Phil_V; 07-09-2009 at 05:18 PM.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Search for matching text, then delete rows above it.

    Not by me, Phil. Had you posted it after my request for a thread title change, I'd have soft-deleted it and restored it after the title was changed.

  6. #6
    Registered User
    Join Date
    07-08-2009
    Location
    PA, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Search for matching text, then delete rows above it.

    Quote Originally Posted by Phil_V View Post
    I'm sure I posted a solution to this earlier, but it seems to have been deleted along with the sample workbook that had been uploaded previously?
    Phil, you did post a reply, but it was for a duplicate thread. Oops
    Now if only I can figure out how to delete this old one.....

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Search for matching text, then delete rows above it.

    Well, I didn't keep a copy of my previous code, but this is my 'submission':

    Please Login or Register  to view this content.
    This will also remove the surplus blank lines that are otherwise left by shg's code.
    Also note that my find text is "UID: ", as in the earlier post it was stated that the "=" was a mistake and the data actually had ":" instead.


    I wasn't accusing you shg, I hope you understand that, just wondered where the earlier responses had gone.

    EDIT I KNEW I'd seen it somewhere before, seems posts weren't deleted, just a very bad case of cross-posting on the same forum
    See here:
    I need code to search for certain text, then delete the row, plus others. $30 REWARD
    Last edited by Phil_V; 07-09-2009 at 05:34 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Search for matching text, then delete rows above it.

    Phil,

    It's still posted at http://www.excelforum.com/excel-prog...30-reward.html

    ... but it was for a duplicate thread. Oops
    mainer, please don't do that again.

  9. #9
    Registered User
    Join Date
    11-08-2013
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2011
    Posts
    0

    Re: Search for matching text, then delete rows above it.

    Quote Originally Posted by shg View Post
    Thank you.

    Try this:
    Please Login or Register  to view this content.
    This works wonderfully for my application, but "UID" shows up in more than one column so its deleting too much data. Is there a way to specify that I only want it to fine "UID" in column A and then delete its row and the three rows above?

+ 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