+ Reply to Thread
Results 1 to 9 of 9

removing duplicates from data

  1. #1
    Registered User
    Join Date
    06-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    46

    removing duplicates from data

    Hi All,

    I am trying to write a piece of code that helps me to remove duplicates from my data and cleans up the results.
    The code should find duplicates in the same colum and copy the data in the rows of these duplicates to one row (the one of the first duplicate). Then it should delete the now empty duplicates and move on to the next set of duplicates.
    See the attached file for a before and after.

    I hope I make myself clear, any help is greatly appreciated!

    Thanks!
    Schzuki
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: removing duplicates from data

    Output is on sheet2.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: removing duplicates from data

    Thanks AB33! As I am kind of a novice, would you mind explaining me what the code does?

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: removing duplicates from data

    AB33, this is great!!!

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: removing duplicates from data

    The code uses a dictionary script to store unique keys in column A. If the key is already exists on the dictionary, it looks for that row if it is empty, if it is ,it brings up that row with the initial key row. I have also used arrays to store the range values. If you are new to VBA, you may be overwhelmed with jargons and alien language. I do not know how to simplify it, so that you can easily understand it.
    Last edited by AB33; 11-14-2013 at 08:25 AM.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: removing duplicates from data

    Berlan,

    Thank you

  7. #7
    Registered User
    Join Date
    06-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: removing duplicates from data

    haha, I do get the general principle, now it's just the matter of understanding the pieces of code (yeah for google!).
    Thanks for taking the time to explain!

  8. #8
    Registered User
    Join Date
    06-03-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: removing duplicates from data

    okay, let's see if I got this:

    You Dim the different variables as string ($) and long (&). What is the name of the type of data that is assigned to y (the () part)?

    The code selects a range y and sets its size to the same size as the original data range (=(10,4)).

    It then creates a library object. Within this library, comparisons are made between string values (.CompareMode=1)

    It then runs through the data until the last value (=UBound)

    The If-function is stil a bit of a mystery. (I don't get the .exists and .item commands)
    However, it reorganises the data into range y.


    Subsequently it clears a range in sheet2 and pastes range y into these cells.

    Could you please explain the different steps in the IF-function?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: removing duplicates from data

    If no data type is assigned to a variable, by default it means it is a Variant type.

    The If-function is stil a bit of a mystery. (I don't get the .exists and .item commands)
    However, it reorganises the data into range y.

    This line test the key using dictionary script. As I mentioned earlier, It will take me the whole page of this site to explain line by line. I suggest you refer to VBA help on dictionary and other loops. But I were you, I first get the grips with arrays.

+ 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. Replies: 2
    Last Post: 08-30-2013, 06:30 AM
  2. Removing Duplicates in Excel - based on most recent data?
    By Womble1986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2012, 10:24 PM
  3. Removing Duplicates in one column and summarizing data
    By guard23 in forum Excel General
    Replies: 5
    Last Post: 02-09-2012, 03:33 PM
  4. Removing Duplicates and Mainting Data - Help!
    By seank in forum Excel General
    Replies: 1
    Last Post: 08-18-2009, 08:51 AM
  5. merge data from array without removing column duplicates
    By aversluis in forum Excel General
    Replies: 3
    Last Post: 09-26-2007, 12:48 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