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
Bookmarks