There are a lot of ways you can do this, I guess it just depends on how you want to do it. One way would be for you to hard code each time the max and the min row. (like this)
With ActiveSheet
lrow = 500 'or whatever you want
minrow = 2 'or whatever you want
For i = lrow To minrow Step -1
If .Range("B" & i).Value = .Range("B" & i - 1).Value And .Range("D" & i).Value < .Range("D" & i - 1).Value Then
.Rows(i & ":" & i).Delete
lrow = lrow - 1 'this part will stop when it reaches the minimum row number variable
End If
Next i
End With
Another way would be to prompt yourself with 2 input boxes prior to the code running (something like this)
With ActiveSheet
lrow = Application.InputBox("Enter the max row")
minrow = Application.InputBox("Enter the min row")
For i = lrow To minrow Step -1
If .Range("B" & i).Value = .Range("B" & i - 1).Value And .Range("D" & i).Value < .Range("D" & i - 1).Value Then
.Rows(i & ":" & i).Delete
lrow = lrow - 1 'this part will stop when it reaches the minimum row number variable
End If
Next i
End With
*Note: I left out a lot of error checking here
You could also build a userform and just collect the info once each time. Many more ways to do it, i figured i would give you these ones.
Bookmarks