+ Reply to Thread
Results 1 to 14 of 14

Remove Duplicates Code

  1. #1
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Thumbs up Remove Duplicates Code

    Hi Guys & Gals,

    I have attached a very interesting scenario with VBA code to remove duplicates. This code, I presume, is widely used, and yet, see how it can FALTER.

    Is there any other more reliable approches I could consider?
    Last edited by Winon; 11-18-2011 at 04:27 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Code

    Filters (Auto and Advanced) require a header row.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    Hello shg,

    Thank you for responding.

    What I do not understand though, is that the code never did this before, even without header rows.

    Why the disparety between lists 1 and two?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Code

    The filter regards the first row as a header. 'Twas ever thus.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Remove Duplicates Code

    To back up shg (not that he needs it!)

    Advanced filter is treating "COMMUTER 1" and "D/PACK" as headers and returns them, as D/PACK is also in the list (allowing for the header) you're getting what appears to be a duplicate.

    You could try including the headers from Sheet2 (without the spare blank row), or just this.
    Please Login or Register  to view this content.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    Thank you guys,

    I am getting it now. But Please can you the explain why VP 1005 from List 2 also appears twice?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Code

    The second one has a trailing space.

  8. #8
    Registered User
    Join Date
    08-23-2011
    Location
    NYC
    MS-Off Ver
    Excel 2019/O365
    Posts
    60

    Re: Remove Duplicates Code

    Nice, I can definitely use this one.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    Hi shg,

    Please do not ask me how I missed that trailing space. Embarassing, to say the least. But then again it would require some vba checking and clearing when users make such mistakes. Or is it not do-able?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Code

    The VBA Trim function removes leading and trailing spaces.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    Hi Internoob2,

    Glad you like it, just make sure to take heed of what shg and Marcol suggested to improve on it. I did, and it now goes like a ROCKET!

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    Thank you shg,

    Do you think there is a way to incorporate that Trim Function into the Module which Marcol so kindly amended to Header:=xlNo ?

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Remove Duplicates Code

    I'm sure Marcol could do it for you readily, but just adding it in the remove duplicates code probably makes little sense. It should be performed at the appropriate point in the process flow when you collect the data.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Remove Duplicates Code

    You are just so helpfull shg,

    Thank you.

    Maybe I should try and see if I could do the VBA-Trim in the BeforeClose_Event of the WB the data is imported from. Promise to bother you again in this regard if I may.

    Until later,

    Take care !

    You & Marcol were just absolutely fantastic in the pointers!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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