+ Reply to Thread
Results 1 to 9 of 9

Delete row if column does not have a word

  1. #1
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Delete row if column does not have a word

    If a row between row 2 and row 5000 does not contain the word alpha in column M, I would like it deleted. Wondering best way to do this via macros.
    Last edited by undergraduate; 05-07-2010 at 03:21 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete row if column does not have a word

    Easiest way is with the Data > Filter > Autofilter. Turn that on and filter than column by Custom: Does not contain: alpha. Then delete all rows left visible. Turn off the Autofilter.

    You could record that into a macro in seconds.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Delete row if column does not have a word

    thank you that should work!
    Please Login or Register  to view this content.
    Last edited by undergraduate; 05-07-2010 at 03:31 PM.

  4. #4
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Delete row if column does not have a word

    Actually, I was just wondering is there any way to make alpha a variable instead so in other words.
    Criteria1:=<>variable, would that work?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete row if column does not have a word

    Undergraduate, if you haven't read through the Forum Rules, do so now so you can use and follow them effectively. For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    Your code appears to clear data, not delete the rows, this would leave a vast number of blanks all through your data set. Might I suggest:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-07-2010 at 03:35 PM. Reason: corrected code to delete entire rows

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete row if column does not have a word

    For a variable:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-07-2010 at 04:00 PM. Reason: Corrected code to delete entire rows

  7. #7
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Delete row if column does not have a word

    Thank you that is useful, I apologize for not abiding by the rules.

  8. #8
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Delete row if column does not have a word

    I tried running at again a second time and its just deleting everything, since the criteria is variable shouldnt be something like criteria1=<>MyVar?

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete row if column does not have a word

    Duh...yes, my bad, you're absolutely right. (headbang)

    Please Login or Register  to view this content.


    Also, this is an exact match filter. Are you sure don't want to allow for partial matches?
    Please Login or Register  to view this content.

+ 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