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
Last edited by step_one; 06-29-2011 at 07:24 PM.
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:
- 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
- Open the copy of the Excel workbook you want to modify
- Use the keyboard shortcut ALT+F11 to open the Visual Basic Editor
- Insert -> Module
- Copy/Paste the code into that area
To run a macro in a workbook:
- In Excel (not the Visual Basic Editor) press the keyboard shortcut ALT+F8
- Double-click the desired macro (I named this one RemoveDuplicatesMacro_for_step_one)
Hope that helps,
~tigeravatar
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks