+ Reply to Thread
Results 1 to 23 of 23

Remove rows based on word in column

  1. #1
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Remove rows based on word in column

    Hello I am trying to remove rows based on the below code however I need to add another criteria, the word pink. How should the code be edited? I have tried to add Operator:=xlAnd, Criteria3:="<>*pink*" but that gave an error.

    Please Login or Register  to view this content.

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

    Re: Remove rows based on word in column

    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

  3. #3
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Mis match error seen here http://screencast.com/t/SHRPMAxSezm

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: Remove rows based on word in column

    Googling a bit it seems one can only use two criterias with wildcard in an array but perhaps this link could provide a workaround?

    https://social.msdn.microsoft.com/Fo...d?forum=isvvba

    Alf

  5. #5
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Thanks however I am not good at structuring code. Can you show me how it should look with the tree criteria I am trying to use?

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

    Re: Remove rows based on word in column

    Try this for a workaround:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    compilation error, argument not optional and it highlighted the word Range after "For Each R In" http://screencast.com/t/bLpklSnbf6qQ

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

    Re: Remove rows based on word in column

    My Bad

    Try:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Thanks, but the code is stuck or its just running really slow. Am performing this on a file with around 100k rows. Is there any other alternative?

  10. #10
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    I think it got hung up because this http://screencast.com/t/NtpTcMKK then it highlighted this row "R.EntireRow.Hidden = True"

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

    Re: Remove rows based on word in column

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,500

    Re: Remove rows based on word in column

    This works fine for me.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  13. #13
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Quote Originally Posted by bakerman2 View Post
    This works fine for me.
    Please Login or Register  to view this content.
    Object required error then it highlighted this code ".Rows.Hidden = False"

  14. #14
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: Remove rows based on word in column

    It seems to me that since your original macro works getting rid of *test* and *black* why don't just add some lines doing away with *pink* after getting rid of *test* and *black*

    Alf

  15. #15
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215
    Quote Originally Posted by Alf View Post
    It seems to me that since your original macro works getting rid of *test* and *black* why don't just add some lines doing away with *pink* after getting rid of *test* and *black*

    Alf
    The original macro does not get rid of lines with the colors specified, it keeps them. So adding a line will not work because the values would have already been deleted from the first set of lines

  16. #16
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Really I am just looking for code the keeps all rows if they have any of those three words in field 10 column and delete all other rows.

  17. #17
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,500

    Re: Remove rows based on word in column

    Please Login or Register  to view this content.

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

    Re: Remove rows based on word in column

    Maybe:

    Please Login or Register  to view this content.

  19. #19
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,500

    Re: Remove rows based on word in column

    Since I'm convinced that looping through a 100k rows is not such a good idea I'd like to present an alternative.
    It also performs a loop but this one is done in memory which runs much faster then on sheet.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 06-06-2016 at 09:46 AM.

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

    Re: Remove rows based on word in column

    Or, a block hide:

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Re: Remove rows based on word in column

    Quote Originally Posted by bakerman2 View Post
    Please Login or Register  to view this content.
    I have decided to try the above code since it was the first one mentioned and it seems to work just fine. Is this okay to continue using?

  22. #22
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,500

    Re: Remove rows based on word in column

    You mentioned before you have about 100k rows.
    It all comes down on how fast you want it to be executed. Looping on worksheet is slow, so for faster execution (IMHO) I'd try code from post#19 and make comparison.

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

    Re: Remove rows based on word in column

    And, compare with post#20 - please

+ 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. Remove rows based on word in column
    By wonderd in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-05-2016, 11:59 PM
  2. Replies: 4
    Last Post: 01-08-2016, 09:21 AM
  3. Deleting rows based on partial word in certain column
    By bmckenzie93 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2014, 03:51 PM
  4. Replies: 5
    Last Post: 05-08-2014, 07:24 AM
  5. Remove rows with duplicate values in one column based on value of another column
    By jolleyje in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-15-2013, 06:20 AM
  6. Moving Rows From Main doc based on word in column
    By Greggatm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2013, 08:43 PM
  7. [SOLVED] Remove rows based on duplicates in certain columns, and merge data from another column
    By yanagi600 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-02-2013, 04:17 PM

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