+ Reply to Thread
Results 1 to 8 of 8

Delete rows based on non-matching criteria (Exceptions)

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    97

    Delete rows based on non-matching criteria (Exceptions)

    G'day Code Masters

    I have a list of names in Column B (from B6) on Sheet2 which represent the names I always want retained. There is only one instance of each name.

    I also have a list of names in Column G (from G5) on Sheet1. This list is produced each month, with some names returning and new ones appearing. There can be multiple instances of the same name.

    On Sheet1, I always want to keep (the entire row of) those entries that match the names on Sheet2. All the rest are to be deleted (delete the entire row).

    Example:

    If Steven Hawking appears on Sheet1, and his name is also on Sheet2 (the names I always want to retain), then all instances of his name stay on Sheet1.

    If Mick Jagger appears on Sheet1, and his name is NOT on Sheet2, then for all instances of his name, the entire row gets deleted.

    The code continues looping through the entire name list on Sheet1 until finished. A message box at the end advising the total entries removed would be useful but is not essential.

    Note: I have some working code already in the workbook module but unfortunately it does the process the wrong way round!

    Thanks
    Attached Files Attached Files
    Last edited by Rabbitoh; 09-11-2020 at 04:08 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Delete rows based on non-matching criteria (Exceptions)

    See if this works.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Delete rows based on non-matching criteria (Exceptions)

    Another Option...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Delete rows based on non-matching criteria (Exceptions)

    This is excellent and does exactly what is required. Thank you

  5. #5
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Delete rows based on non-matching criteria (Exceptions)

    Thank you Sintek. This one is a variation on the last one you so excellently provided me. Unfortunately, it deletes everything on sheet1, including the ones that were to be kept. Want to have another go so I can add to your rep?

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Delete rows based on non-matching criteria (Exceptions)

    Unfortunately, it deletes everything on sheet1, including the ones that were to be kept
    That is because your calculation is set to manual...Go to settings and change it to automatic and the code will work correctly...
    Or use this snippet...
    Please Login or Register  to view this content.
    Last edited by sintek; 09-12-2020 at 07:30 AM.

  7. #7
    Registered User
    Join Date
    07-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Delete rows based on non-matching criteria (Exceptions)

    Wow, I didn't know there was such a thing. Have changed and now works excellent. Thank you once again.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Delete rows based on non-matching criteria (Exceptions)

    Glad to have contributed...Tx for rep +

+ 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] loop multiple criteria & delete matching rows?
    By Quint6778 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-09-2017, 09:58 AM
  2. [SOLVED] Objective: delete rows based on multiple criteria matching
    By Quint6778 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2017, 05:25 PM
  3. [SOLVED] DELETE Rows in SQL db table matching criteria via EXCEL VBA
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2016, 07:03 PM
  4. Macro to delete rows based on two different criteria matching
    By Cpower17 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-25-2014, 05:43 PM
  5. [SOLVED] Mark or Delete Rows based on Matching Multiple Criteria in another worksheet
    By clearbluez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2012, 02:38 PM
  6. delete rows not matching certain criteria
    By sanketgroup in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2011, 04:04 PM
  7. How to delete rows with exceptions in different columns
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2011, 05:19 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