+ Reply to Thread
Results 1 to 27 of 27

Delete duplicates but copy some entries

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Delete duplicates but copy some entries

    Hello,

    I have this code to delete duplicates based on highest value in column "B"

    Please Login or Register  to view this content.
    I need from formula to check, if in columns "C", "D" or "E" are any entries and merge them to row with highest value in column "B" before deleting the rows.
    Last edited by misop; 09-13-2012 at 03:00 PM.

  2. #2
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    Column A B C D E F ... at all 94 columns

    A0001 1 AAAAAA asdsdas
    B0001 1 CCCCCC 01.01.2010 DDDDD
    C0001 1
    A0015 1
    A0001 2 01.01.2000 BBBBBB
    A0002 1
    B0001 2
    A0001 3 xxxxxx

    In the end I want to have this:

    Column A B C D E F

    C0001 1
    A0015 1
    A0002 1
    B0001 2 CCCCCC 01.01.2010 DDDDD
    A0001 3 AAAAAA 01.01.2000 BBBBBB xxxxxx

  3. #3
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    no one can help me? or it is impossible?

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Do you have a excel sample file that you can upload?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    of course, here it is
    Last edited by misop; 09-13-2012 at 04:34 AM.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    So only columns C, D and E should be merged with the highest value row?

  7. #7
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    yes, i want to merge only this 3 columns, other columns will be only from the row with highest number in column B

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Try this code
    Please Login or Register  to view this content.
    Put it in a standard module.

  9. #9
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    GREAT IT WORKS...

    only thing I should done now is, after deleting rows, sort data from oldest to newest: date will be in column "CO"
    Last edited by misop; 09-12-2012 at 03:32 PM.

  10. #10
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    Now I get this error: Run-time error 1004: The sort reference is not valid. Make sure that its within the data you want to sort, and the first Sort Box isnt the same or blank

    it highligt this part:

    Please Login or Register  to view this content.
    Last edited by misop; 09-13-2012 at 05:51 AM.

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Your sort code should be -
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    Here is whole code with sorting on column CO too:

    Please Login or Register  to view this content.
    Last edited by misop; 09-13-2012 at 06:21 AM.

  13. #13
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    One time it works and when i try it again... it gave me the same error

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Your sort shows that its sorting on A & B columns. You need to change this code to sort on column CO. So you only need one -
    Please Login or Register  to view this content.
    What is this code that you have below -
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    It is good to first time sort on columns A & B so i think that code is correct

    After cleraing database (deleting and marging rows) i need again sort data on column CO and that makes this code:

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Please Login or Register  to view this content.
    line is incomplete. You need to put in the row number for CO. You have only put the column.

  17. #17
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    that was my mystake, I repaired that after posting here...

    I give sample of my data and try to sort them, delete rows... with code you gave me... button "Tlačidlo"

    It works for me every second or third thry... i dont understand... sometimes it game me error, sometimes not..
    Attached Files Attached Files

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Is your file in excel 2003 or 2010?

  19. #19
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    in file format 2003, but i am workin with it in 2013

  20. #20
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    The file is in 2003, right? So the sort code will not be compatible for excel 2003.

  21. #21
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    yes it is in 2003... why it is not compatible... is that possible to write macro for 2003? I think it can work than in 2003, 2007, 2010, 2013 right?

  22. #22
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    The sorting code in 2003 is completely different than 2007 and onwards with respect to syntax.

    This is a sample of a 2003 sort code
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    so i must replace this code:

    Please Login or Register  to view this content.
    with this code?

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    Yes and change the cell references where required.

  25. #25
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    with this code:

    Please Login or Register  to view this content.
    it only sort data, but it dont delete any row...

  26. #26
    Registered User
    Join Date
    11-09-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Delete duplicates but copy some entries

    I think I found solution
    Please Login or Register  to view this content.
    it seems to work

  27. #27
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete duplicates but copy some entries

    You need to edit this code slightly. Change this from
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Note: If you do not make out the changes, i have put "." before the ranges, since you have the With statement before them.

+ 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