+ Reply to Thread
Results 1 to 6 of 6

Loop through a range and delete duplicate rows. (Check data in two columns)

  1. #1
    Registered User
    Join Date
    12-05-2014
    Location
    Hanoi, Vietnam
    MS-Off Ver
    MAC
    Posts
    9

    Loop through a range and delete duplicate rows. (Check data in two columns)

    Hi all,

    I have a list of names in Column A including duplicates and some names are marked in Column C.

    What I would like a VBA macro to do is to loop through the range, find the FIRST name in column A in combination with a "Yes" mark in column C, and delete all duplicate rows containing the same name.

    -If there are multiple rows with the same name and a "Yes" mark, the code should keep the first Row containing both and delete all other duplicate rows.
    -Nothing will happen to rows that don't have duplicates.

    Please Login or Register  to view this content.
    So, after the code looped through the range the result will be:

    Please Login or Register  to view this content.
    Row 1 contains the first Jason and is marked "Yes" in Column C. Therefore all other rows containing Jason can be deleted from the list.
    Row 2 had Sarah in it but was empty in Column C. The first row that contains Sarah in combination with a "Yes" in Column C has priority and so Row 7 should stay and other duplicate rows with Sarah should be deleted. etc.
    Row 5 has no duplicate row so row 5 stays in the list.


    Any suggestions?

    Many thanks in advance.
    Attached Files Attached Files
    Last edited by spikedemike; 10-15-2015 at 12:50 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Loop through a range and delete duplicate rows. (Check data in two columns)

    Try such code:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Loop through a range and delete duplicate rows. (Check data in two columns)

    Another one for what it's worth

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    12-05-2014
    Location
    Hanoi, Vietnam
    MS-Off Ver
    MAC
    Posts
    9

    Re: Loop through a range and delete duplicate rows. (Check data in two columns)

    Many thanks Kaper and Alphafrog,

    I appreciate all your efforts helping me out.
    It seems that Kaper's code does the work perfectly, but I still have a question.

    What if the data is not on the first row but starts on the second or third? I've attached my file.
    I've tried to change the values in the code but It doesn't seem to work.
    Attached Files Attached Files
    Last edited by spikedemike; 10-15-2015 at 04:34 AM.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Loop through a range and delete duplicate rows. (Check data in two columns)

    Corrected to fit new layout:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-05-2014
    Location
    Hanoi, Vietnam
    MS-Off Ver
    MAC
    Posts
    9

    Re: Loop through a range and delete duplicate rows. (Check data in two columns)

    Thank you so much, Kaper.

    This code works great. an other thanks for some comments so I can TRY to make some sense out of it.

+ 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] Move data on duplicate rows (different columns) to one row and delete extra rows?
    By Sagwa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2014, 08:25 AM
  2. [SOLVED] Delete rows that have duplicate data in certain columns
    By aarodn in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2013, 07:48 PM
  3. Replies: 6
    Last Post: 03-04-2013, 12:03 AM
  4. Duplicate rows, delete columns w/same data, combine columns w/unique data, Mac Excel 2011
    By msmcoin in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 02-03-2013, 02:10 PM
  5. Macro to check for duplicate rows by comparing columns A,B,C,D,E,F,G, H, & I.
    By Huckleberry14 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-27-2012, 10:32 AM
  6. Delete duplicate rows with same data in certain columns for million rows
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-08-2012, 12:53 AM
  7. Delete Duplicate Rows based on All columns
    By king12yan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2010, 02:36 PM
  8. Delete duplicate rows based on all columns
    By kiran654 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-30-2010, 08:14 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