+ Reply to Thread
Results 1 to 13 of 13

Delete rows based in three criteria in three separate columns

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

    Delete rows based in three criteria in three separate columns

    Example: I have a list of 100 names on sheet1 along with other data in other columns (A - date, B - number, C - address. D - first name, E - middle name, F- last name). and a smaller list of 10 names (A - first name, B - middle name, C - last name) on sheet2. All the names on sheet2 are considered "exceptions" and as such I use the following code to remove every row where the instance of each of them appear on sheet1.

    However, the code only works based on one criteria in one column i.e. the name in column D. What I need it to do is to work based on three criteria over three columns e.g. instead of just deleting every row in Column D of sheet1 where "John" appears, I need it to identify and delete every row where "John" appears in Column D, AND "Peter" in Column E, AND "Smith" in Column F. So three columns and three criteria to be met before the row is deleted. If "all three names" "in the same order" as they appear on sheet2 two are not present then the row is not deleted.

    The code below searches the full row to find "John" rather than specifying a specific row. I hope a codemaster can help.

    Please Login or Register  to view this content.
    Last edited by Rabbitoh; 09-05-2020 at 03:40 AM.

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

    Re: Delete rows based in three criteria in three separate columns

    And DrumRoll....

    A sample file with exact setup as Main File is...
    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!!!

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Delete rows based in three criteria in three separate columns

    you did not add an excel file, so I can't test it for you.

    Column D1 = A1&B1&C1

    After that make compare D1 with the list in sheet 2.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

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

    Re: Delete rows based in three criteria in three separate columns

    Attachment attached, I think
    Attached Files Attached Files

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Delete rows based in three criteria in three separate columns

    I would use Power Query to do this.
    Load your data to PQ (if you don't have this already, you can download the add in from MS. It is native to Excel versions 2016 and later and found on the Data Tab.)
    Merge the three columns and place a colon as the delimiter.
    Filter out the necessary item
    Split the field on the delimiter
    Close and Load to Excel

    Here is the Mcode

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

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

    Re: Delete rows based in three criteria in three separate columns

    I have a list of 100 names on sheet1 along with other data in other columns (A - date, B - number, C - address. D - first name, E - middle name, F- last name). and a smaller list of 10 names (A - first name, B - middle name, C - last name) on sheet2
    This tells me that your sample file is not a accurate representation of your actual file????
    We can supply code and 99% of the time, a member will not be able to amend it for actual file...Meaning...valuable time is wasted on unnecessary code writing...

    So do a favour and upload a sample file with accurate representation...

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

    Re: Delete rows based in three criteria in three separate columns

    Correct attachment attached (my bad, I had a simplified copy for playing around with)
    Attached Files Attached Files

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

    Re: Delete rows based in three criteria in three separate columns

    Done. Corrected as requested

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

    Re: Delete rows based in three criteria in three separate columns

    Thank you...This should always be the case for future threads...
    Please Login or Register  to view this content.
    Last edited by sintek; 09-05-2020 at 06:58 AM.

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

    Re: Delete rows based in three criteria in three separate columns

    I agree and will do so. This code works perfectly. Thanks for doing what you do.

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

    Re: Delete rows based in three criteria in three separate columns

    .........................
    THANKS.gif

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

    Re: Delete rows based in three criteria in three separate columns

    My version of Excel does not support this add-in. If I upgrade, will the code generated by Power Query allow the worksheet to function correctly in any version of Excel, or will it always require 2016 or greater?
    This post of course relates back to the post from alansidman in respect to the POWER QUERY add-in, which sounds like something I should have going forward anyway.
    Last edited by Rabbitoh; 09-05-2020 at 07:39 AM.

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Delete rows based in three criteria in three separate columns

    An alternative is to again use Power Query and join the two tables with a Right Anti Join.

    Here is the Mcode.
    Please Login or Register  to view this content.
    Excel 2016 (Windows) 32 bit
    A
    B
    C
    D
    E
    F
    1
    Table1.Date Table1.Number Table1.Address Table1.First Name Table1.Middle Name Table1.Last Name
    2
    1/1/2020
    15
    123 Street John Arthur Smith
    3
    1/20/2020
    4
    123 Street Michael James Jones
    4
    2/15/2020
    9
    123 Street Enda Mary Smith
    Sheet: Sheet4


    1. In Version 2010 and 2013, you need to download the add in from MS. Power Query will work in any machine either having the add in or 2016 and later versions. Click on the link in my signature block to learn more about PQ.

    2. If this is something you wish to explore further, the book "M is for (Data) Monkey" by Ken Puls and Miguel Escobar is a great primer. This is a very powerful piece of Excel and will allow you to easily manipulate data without learning code.
    Last edited by alansidman; 09-05-2020 at 07:48 AM.

+ 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. split/separate rows based on criteria and send those rows by mail
    By katu in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-09-2014, 08:59 AM
  2. Find and Delete rows based on criteria in multiple columns
    By Doctor_H in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2013, 08:03 PM
  3. [SOLVED] Delete Rows based on criteria in two columns
    By KSSLR in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-30-2013, 04:39 PM
  4. Lookup value based on 2 criteria in 2 separate columns
    By mattadler22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-17-2013, 05:59 PM
  5. extracting rows of data from a table that are met by criteria in two separate columns
    By markhocek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2013, 03:20 AM
  6. [SOLVED] Delete Rows Based on Data in Separate Worksheet
    By Smitty7 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-27-2012, 05:48 PM
  7. VBA code to sum a range based on criteria in two separate columns
    By new.vbacoder in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2010, 02:16 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