+ Reply to Thread
Results 1 to 8 of 8

How to delete rows that contain certain text in a cell using a formula

  1. #1
    Registered User
    Join Date
    05-27-2014
    Posts
    5

    Exclamation How to delete rows that contain certain text in a cell using a formula

    Hi

    I'm working with a really long excel sheet/project where I have to delete rows that contain the text: "OTHER (COMBINED) COUNTIES" ...among other text in a cell in the B column. Is there some sort of formula I could use to have this done automatically throughout the excel sheet? I've looked up in other posts but they all say to include a formula in the macros or VBA, but Im a newbie at this and have no idea how to do that. So could someone give me a step by step?

    Attached is a picture with what I am working with

    vanessa work.jpg

    p.s. this is pretty urgent since this project I'm working on is due this Friday and I'm freaking out I haven't been able to figure this out :/

    Thanks!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to delete rows that contain certain text in a cell using a formula

    If it's pretty urgent, I'd recommend attaching a real example of your work. It's going to take me a couple of hours to recreate your picture from scratch.

    Other than that you might have luck with a filter with copy and paste, a few hundred array formulas, or... VBA which could do it all in less than a second.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    05-27-2014
    Posts
    5

    Re: How to delete rows that contain certain text in a cell using a formula

    Here's the file I'm working with.

    Acreage,Yield, Production and Price for SOYBEANS .xls

    Also, I have several other workbooks I'm working with that I'll have to do the same thing to, could I just copy and paste the same macro or formula there too?

    Thanks!

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to delete rows that contain certain text in a cell using a formula

    Here's on macro that can do it. First, copy the tab's headers to another tab.

    In order to use VB:
    • copy the code below
    • go to Excel
    • Hit Alt+F11
    • Go to Insert -> Module
    • Paste the code in the window that opens
    • Close that window

    Please Login or Register  to view this content.
    Now go back to the first tab, hit Alt+F8 and run your macro. Every line without that in it will copy over.


    The attached is ready to go.
    Attached Files Attached Files

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to delete rows that contain certain text in a cell using a formula

    I looked around and found a MUCH faster and simpler method.

    Change the code between the asterisks as needed to whatever you want to delete. This instantly kills all rows you want out, and it does it in place without copying anywhere else.

    VB code:

    Please Login or Register  to view this content.

    Broken apart:

    Sub Filter()
    With ActiveSheet
    .AutoFilterMode = False
    With Range("B2", Range("B" & Rows.Count).End(xlUp)) = from B2 to the last non-blank cell
    .AutoFilter 1, "*OTHER (COMBINED) COUNTIES*" =look for this
    On Error Resume Next
    .Offset(1).SpecialCells(12).EntireRow.Delete =delete each row that has it
    End With
    .AutoFilterMode = False
    End With
    End Sub[/CODE]

  6. #6
    Registered User
    Join Date
    05-27-2014
    Posts
    5

    Re: How to delete rows that contain certain text in a cell using a formula

    Awesome! Thanks so much! It worked

    Also, now I have to delete rows that have a duplicate cell in row B. So in row B I only need rows that have unique cells, delete evry other row where the cell in B column is duplicated. Doesnt matter which Cell is deleted. Basically I just want a list of the counties in row B. Is there a way to do this?

    Thanks!

  7. #7
    Registered User
    Join Date
    05-27-2014
    Posts
    5

    Re: How to delete rows that contain certain text in a cell using a formula

    Actually just saw that excel has a preinstalled function in the ribbon, for this. Thanks anyway!

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to delete rows that contain certain text in a cell using a formula

    Hurray! Happiness for everyone.

+ 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. [SOLVED] Find row cell containing specific text, then delete all rows ABOVE that cell
    By ks100 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-20-2013, 02:02 PM
  2. [SOLVED] delete rows that do not contain the text from a specific cell
    By Vogelmann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2012, 03:10 AM
  3. [SOLVED] Code to delete rows that do not contain certain text in a cell
    By rwgladwin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2012, 07:45 AM
  4. [SOLVED] Formula to add or delete rows if no text
    By slohman in forum Excel General
    Replies: 4
    Last Post: 03-31-2012, 07:42 AM
  5. Delete Rows based on cell value and then Insert rows alternatively with a formula
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-11-2008, 04:27 PM

Tags for this Thread

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