+ Reply to Thread
Results 1 to 3 of 3

duplicate issue

Hybrid View

step_one duplicate issue 06-29-2011, 06:00 PM
tigeravatar Re: duplicate issue 06-29-2011, 06:38 PM
step_one Re: duplicate issue 06-29-2011, 07:09 PM
  1. #1
    Forum Contributor
    Join Date
    04-27-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    113

    duplicate issue

    Hello

    Im having some trouble trying to remove duplicates.

    I have attached a sample workbook. Basically, column J (invoice #) has duplicates, however I would like to remove the duplicate but keep the larger of the value from column M

    i.e.
    cell A1: invoice # 0300, column M = 8
    cell A543: invoice # 0300, column M = 6

    so I would prefer if A1 is selected.

    Ive been stuck on this issue for some time and I'm not sure how to tackle the problem! can someone pls advise!

    thx you
    Attached Files Attached Files
    Last edited by step_one; 06-29-2011 at 07:24 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: duplicate issue

    step_one,

    Give this a try:
    Sub RemoveDuplicatesMacro_for_step_one()
        
        Const DupCol As String = "J"
        Const StartRow As Long = 9
        
        Dim LastRow As Long: LastRow = Cells(Rows.Count, DupCol).End(xlUp).Row
        Dim rngFound As Range
        Dim RowIndex As Long, MVal As Double
        
        For RowIndex = LastRow To StartRow Step -1
            If Cells(RowIndex, DupCol).Value <> vbNullString Then
                MVal = Cells(RowIndex, "M").Value
                Set rngFound = Range(Cells(StartRow, DupCol), Cells(RowIndex - 1, DupCol)).Find(Cells(RowIndex, DupCol).Value)
                If Not rngFound Is Nothing Then
                    If Cells(rngFound.Row, "M").Value > MVal Then
                        Cells(RowIndex, DupCol).EntireRow.Delete xlShiftUp
                    Else
                        rngFound.EntireRow.Delete xlShiftUp
                    End If
                End If
            End If
        Next RowIndex
        
    End Sub


    To add a macro to a workbook:
    1. Save a copy of the Excel workbook you want to modify
      • Always test macros in a copy so that the original is preserved in case the modifications don't go smoothly
    2. Open the copy of the Excel workbook you want to modify
    3. Use the keyboard shortcut ALT+F11 to open the Visual Basic Editor
    4. Insert -> Module
    5. Copy/Paste the code into that area

    To run a macro in a workbook:
    1. In Excel (not the Visual Basic Editor) press the keyboard shortcut ALT+F8
    2. Double-click the desired macro (I named this one RemoveDuplicatesMacro_for_step_one)

    Hope that helps,
    ~tigeravatar

  3. #3
    Forum Contributor
    Join Date
    04-27-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    113

    Re: duplicate issue

    hey bud

    thxs alot! it works flawlessly.

    i verified by countif on the J, and i got no mutiple listing, so it appears to be working great. i really apprecaite your ingenius solution. again, thxs you so much!

    cheers

+ 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