+ Reply to Thread
Results 1 to 5 of 5

Moving duplicates to first empty row (i.e. bottom of list).

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Moving duplicates to first empty row (i.e. bottom of list).

    I have attempted to create a macro which scan cells from column D to find duplicates and move the row where the 'second' duplicate is found (i.e. the one with the highest row number) to first empty row, i.e. right at the bottom of the list.

    As an example, the worksheet has no more than 100 rows, the macro starts to look for the value in D1 and compare it to D2, if the values are the same, then row 2 is moved down to row 100. So on so forth for the remaining cells in column D until a blank row is met, then the macro simply deletes all empty row.

    Here is a sample of the code I have been using:

    Please Login or Register  to view this content.
    The macro runs however it does not provide a consistent outcome according to the source data I use. For example the macro moves rows to the bottom of even if there are no duplicates.

    Any help would be appreciated.

    Thanks,
    Antoine
    Attached Files Attached Files
    Last edited by Folshot; 06-17-2011 at 09:14 AM. Reason: Changed title to [SOLVED]

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving duplicates to first empty row (i.e. bottom of list).

    Like so:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-17-2011 at 11:50 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving duplicates to first empty row (i.e. bottom of list).

    I'm trying to follow the logic. Perhaps if you numbered the original datarows (perhaps in the QTY column) so that at the end we could see where the original rows end up.


    1) Compare D2 to D3,
    - if match move D3 to bottom.
    - If not, move to next comparison, D3 to D4
    2) When you reach the bottom of the original dataset, delete the empty rows

  4. #4
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Moving duplicates to first empty row (i.e. bottom of list).

    Thanks a lot Jerry, the macro is very neat. Included 'On Error Resume Next' in case there are no duplicate, otherwise I would get an error.

    It is weird, the macro does not always run properly, sometimes it seems not to compare the correct cells. For example it starts comparing D2 to D3 then jump straight to compare D4 to D5. Simply add a row of data just before row 2 and you will notice the problem.

    Or simply run the macro on worksheet 'Original Data 1' from Macro - Move Duplicates to bottom rows v1.1.xls

  5. #5
    Registered User
    Join Date
    09-16-2010
    Location
    Glasgow
    MS-Off Ver
    2010
    Posts
    68

    Re: Moving duplicates to first empty row (i.e. bottom of list).

    Actually I just needed to remove the following statement:

    Please Login or Register  to view this content.
    Now it works much better. The whole macro becomes:

    Please Login or Register  to view this content.
    Thanks a lot for your help Jerry.

+ 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