+ Reply to Thread
Results 1 to 5 of 5

VBA to remove duplicates by group

  1. #1
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    VBA to remove duplicates by group

    Column A has ID numbers (always sorted alphabetically). Each ID may appear from 1 to 10 times (usually just 3 or 4).
    In another column (In C for this example but can be from C to Z) are other entries that repeat randomly.

    I need VBA that compares the values in "Newcolumn" to others with the same ID and removes duplicates.
    By this I mean that if "oil" for example, shows up twice (or more) the 2nd (and 3rd) times the cell would be blank.
    There would only be one "oil" for that ID.

    I could probably do this with nested DO loops but I think that would be very time consuming especially since I am not
    sure how I would alter the ranges. Is there an expedient way to accomplish this?
    Please Login or Register  to view this content.
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA to remove duplicates by group

    You mention that the columns can be anywhere form C-Z
    and that column A will hold a sorted list of IDs
    Is there any relationship between the ID and the text in either columns?
    Or just take ID001 and check each column with data and if the value is duplicated clear the contents for that row and then do so for each ID?

    So relish may appear in three or four columns but on a row with a different ID.

    This will be macro with a loop per column but that will be quite fast.

    Let me know if I understood you correctly and if this is what you are requesting?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: VBA to remove duplicates by group

    Would this work? Just adjust the new column index.
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: VBA to remove duplicates by group

    @hans
    I am only interested in group duplicates in a single column and clearing dups from that column only (not clearing the whole row).

    JieJenn, works perfectly. I should have thought of that negative step. Thank you both.

  5. #5
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: VBA to remove duplicates by group

    Good thing I paid attention during class.
    Quote Originally Posted by ChemistB View Post
    @hans
    I am only interested in group duplicates in a single column and clearing dups from that column only (not clearing the whole row).

    JieJenn, works perfectly. I should have thought of that negative step. Thank you both.

+ 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 Duplicates in column and remove blanks
    By geliedee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2015, 07:25 AM
  2. Remove duplicates function not removing duplicates
    By Berilium2 in forum Excel General
    Replies: 3
    Last Post: 04-01-2015, 06:55 AM
  3. remove duplicates in each subtotal group
    By trentq in forum Excel General
    Replies: 1
    Last Post: 04-08-2014, 04:02 AM
  4. Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  5. Replies: 5
    Last Post: 02-28-2012, 02:52 PM
  6. Need VBA code to remove entries if there are duplicates (remove them totally)
    By BrandonFromSingapore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2012, 12:50 AM
  7. Replies: 2
    Last Post: 03-20-2011, 11:19 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