+ Reply to Thread
Results 1 to 11 of 11

VBA for conditional removal of duplicates?

  1. #1
    Registered User
    Join Date
    11-08-2017
    Location
    USA
    MS-Off Ver
    13
    Posts
    7

    VBA for conditional removal of duplicates?

    Hi,

    I am not sure if this is possible, but I am generating a report that needs duplicates removed if a certain condition is met. Namely, I have to catchall duplicates in column C, and if any of those duplicates has a certain status code in column A, all duplicates have to be removed. Is this possible?

    In the sample attached, I need to delete both "A" and "B" entries because one of the duplicates has the status "1" in Column A. I can't just delete all 1's, because it would also need to delete the A and B that have value "2".

    I guess another way to go about it would be to find all 1's and the delete any row that has the same name in column B? I don't know.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA for conditional removal of duplicates?

    "another way to go about it would be to find all 1's and the delete any row that has the same name in column B"
    Yes it is a way to do
    Do you want a macro to do it or are you ready to do it manually ?
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    11-08-2017
    Location
    USA
    MS-Off Ver
    13
    Posts
    7

    Re: VBA for conditional removal of duplicates?

    If that's a possibility, I would greatly appreciate help with a macro!

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: VBA for conditional removal of duplicates?

    So you are requiring the first four rows removed? You would be left with row 6 & 7?

    One quick and easy way, put in C2 copied down >> =COUNTIFS(B:B,B2,A:A,1)

    Now filter column c on the 1's and delete those rows. That can easily be turned into a macro, but is this the direction you desire?
    HTH
    Regards, Jeff

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: VBA for conditional removal of duplicates?

    Try this on a copy of your workbook...

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA for conditional removal of duplicates?

    Here the macro
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-08-2017
    Location
    USA
    MS-Off Ver
    13
    Posts
    7

    Re: VBA for conditional removal of duplicates?

    Yes, the first four rows would fail the condition and be deleted. All that would be left would be the last two.

    And I am ultimately trying to build a macro to achieve this. A complication I may run into though is that there are actually 7-8 statuses that will trip this condition and cause the need for any duplicates to be deleted. Should I add a line to the macro before this that would rename all of the statuses to the same one?

  8. #8
    Registered User
    Join Date
    11-08-2017
    Location
    USA
    MS-Off Ver
    13
    Posts
    7

    Re: VBA for conditional removal of duplicates?

    PCI,

    Awesome! Thanks!!
    Last edited by jeffreybrown; 03-23-2018 at 02:21 PM.

  9. #9
    Registered User
    Join Date
    11-08-2017
    Location
    USA
    MS-Off Ver
    13
    Posts
    7

    Re: VBA for conditional removal of duplicates?

    jeffreybrown,

    Worked perfectly. Thanks!

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: VBA for conditional removal of duplicates?

    You're very welcome. We are happy to help.

    Please mark as solved.

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: VBA for conditional removal of duplicates?

    Quote Originally Posted by scootsy View Post
    A complication I may run into though is that there are actually 7-8 statuses that will trip this condition and cause the need for any duplicates to be deleted. Should I add a line to the macro before this that would rename all of the statuses to the same one?
    Sorry I missed this part, but not sure I understand.

+ 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] Removal of Duplicates reading /invalid rows
    By Ravi_Kadu in forum Excel Formulas & Functions
    Replies: 47
    Last Post: 05-22-2017, 02:46 AM
  2. Macro button to collect data from 2 columns of unknown length & duplicates removal
    By regresss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-29-2015, 05:30 PM
  3. Dynamic removal of duplicates
    By spoursy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-11-2014, 01:56 PM
  4. [SOLVED] Remove Duplicates, Partial Removal
    By DorianGrim in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2013, 03:16 PM
  5. [SOLVED] Removal of duplicates, with conditions.
    By Rob8489 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-07-2013, 10:07 AM
  6. Conditional removal of quotes
    By Datagrunt in forum Excel General
    Replies: 1
    Last Post: 11-25-2009, 07:49 PM
  7. Complete removal of duplicates?
    By dan hs in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 11-10-2009, 07:03 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