+ Reply to Thread
Results 1 to 16 of 16

Clear Cells that do not contain certain text

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Clear Cells that do not contain certain text

    I have text in Col K

    I want to clear all data in Col K where the first two characters is MJ or ZR


    Please Login or Register  to view this content.

    It would be appreciated if someone could kindly amend my code

  2. #2
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Clear Cells that do not contain certain text

    Untested but maybe,

    Please Login or Register  to view this content.
    Happy? Click the * to the left.

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Thanks for the help

    When I run the macro, I get a run time error "Type mismatch" and the code below is highlighted

    Please Login or Register  to view this content.

    Kindly amend this section

  4. #4
    Registered User
    Join Date
    02-22-2016
    Location
    Harare, Zimbabwe
    MS-Off Ver
    2007 & 2010
    Posts
    71

    Re: Clear Cells that do not contain certain text

    Please Login or Register  to view this content.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Clear Cells that do not contain certain text

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Thanks for the help.


    I want all items cleared where the first 2 characters in Col K from row 2 are not MJ or ZR

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Clear Cells that do not contain certain text

    How about
    Please Login or Register  to view this content.
    If you want to clear col K only remove the line in blue, otherwise remove the line in red

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Clear Cells that do not contain certain text

    How about:

    Please Login or Register  to view this content.
    Oops, should have refreshed
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Clear Cells that do not contain certain text

    Please Login or Register  to view this content.
    Last edited by xladept; 05-13-2019 at 01:53 PM.

  10. #10
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Thanks for the help Fluff

    Code works perfectly

  11. #11
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Hi Arkadi


    I replaced .entirerow.delete , with clear contents, but it clears first row

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Clear Cells that do not contain certain text

    You're welcome & thanks for the feedback

  13. #13
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Thanks for the help


    Your code only clears header in 1st row

    I would like all code cleared in Col K from row 2 onwards, the does NOT contain MJ and ZR in the 1st two characters in Col K

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Clear Cells that do not contain certain text

    My code would likely do that if column A doesn't contain data (which is your original criteria for finding the last row). If that column is empty, or CAN be empty, then change the "A" in the LR=... line to another column that does have data consistently.

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Clear Cells that do not contain certain text

    Also, if just trying to clear column K and not the whole row then change:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Clear Cells that do not contain certain text

    Thanks Arcadi

    I have also added the following code to set autofilter off at end of code

    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)

Similar Threads

  1. [SOLVED] Find and Clear certain text from cells
    By xBxW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2018, 12:49 AM
  2. Clear Cells when text in
    By JeDD21 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2017, 04:13 PM
  3. [SOLVED] Clear Contents of cells in red text!
    By Keibri in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-13-2016, 08:01 AM
  4. [SOLVED] Clear cells that do not contain specific text which may be at the beginning or end of cell
    By Sianee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2015, 02:53 PM
  5. [SOLVED] Clear cells with specific text in them
    By nicki_rae22 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-26-2015, 01:36 PM
  6. if column equals text string clear cells
    By wacky_diva in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-18-2013, 08:59 PM
  7. Clear contents of cells that do not contain specific text, sort cells that do
    By feckless.lout in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 01:41 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