+ Reply to Thread
Results 1 to 14 of 14

Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

  1. #1
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi,

    I will appreciate your help. As shown below, I have data from Columns A to D. I want to do the
    following:

    1. Look for duplicates in all column A
    2. For each duplicate found in column A, check if all values in column B are also duplicate.
    3. If the condition in (2) is satisfied, compare column D for all the rows; select the row with the minimum value in column D, and delete the other rows.

    For example:
    A B C D

    Row1: Abby 04/01/2014 7:00PM 0.98437
    Row2: Sam 04/01/2014 9:00PM 0.35627
    Row3: Abby 04/04/2014 7:00PM 0.68932
    Row4: Abby 04/01/2014 7:00PM 0.63132
    Row5: Abby 04/01/2014 7:00PM 0.67532
    Row6: Abby 04/04/2014 7:00PM 0.24932


    Since Rows 1,4 and 5 have the same values in columns A and B; and Row4 value in column E is the smallest value between the 3 rows; Delete Row 1 and 5.

    Same goes with Rows 3 and 6; Delete row 3


    Results
    A B C D

    Row2: Sam 04/01/2014 9:00PM 0.35627
    Row4: Abby 04/01/2014 7:00PM 0.63132
    Row6: Abby 04/04/2014 7:00PM 0.24932


    Thank you for your help!
    Last edited by banawaja; 04-06-2014 at 04:50 AM.

  2. #2
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi,
    I used macro record and you may see a better one from experts.

    Regards,
    tt3
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi tt3,

    Could you just paste the macro you've recorded on the thread? Can't open the attached file right now.

    Thanks!

    banawaja

  4. #4
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Here you go:

    Please Login or Register  to view this content.
    Regards,
    tt3
    Last edited by tuongtu3; 04-06-2014 at 04:13 AM.

  5. #5
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Here you go:

    Please Login or Register  to view this content.


    Regards,
    tt3

  6. #6
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Thanks!
    I'll try this later.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi, banawaja,

    if you use Excel2003 the Sort command and if I remember correctly RemoveDuplicates won´t be available. You would have to work with the old Sort command and maybe use a loop.

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi Holger,

    Runtime Error 1004 appeared when I try to run the macro.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi, banawaja,

    1004 is the worst documented run time error which doesn´t give much of a clue what happened. I downloaded the attachment from tt3 and tested the code on that workbook, no RTE appeared. Could you please attach a sample workbook with the code as you tried to use it to have a look at?

    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi Holger,

    Please see attached file.Time Logs.xls

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

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi banawaja,
    Try the attached.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Thanks Holger!
    I'll try this later on the actual spreadsheet.

    What does x, i&, j&, k&, n& and TT& stand for?

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

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    What does x, i&, j&, k&, n& and TT& stand for?
    &- Long
    TT$-String

    FYI: I am AB

  14. #14
    Registered User
    Join Date
    04-04-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value

    Hi AB,

    Sorry with that confusion. Thanks for help. I'll try it later.


+ 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. Deleting Duplicates across rows
    By caunyd in forum Excel General
    Replies: 3
    Last Post: 08-06-2013, 03:08 PM
  2. Replies: 3
    Last Post: 11-09-2011, 12:36 PM
  3. comparing the column headers, then deleting the entire column iif duplicates occur
    By vindieselgal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2011, 04:53 AM
  4. Comparing Lists and Deleting Duplicates
    By Fcroft in forum Excel General
    Replies: 1
    Last Post: 02-17-2010, 02:01 PM
  5. deleting/retaining duplicates
    By jkrake in forum Excel General
    Replies: 0
    Last Post: 12-06-2005, 01:25 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