• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro for Remove Duplicate rows except last row

Hi,


I have one VBA code with me below is the code:

[pre]
Code:
Sub Row_Dupe_Killer_Keep_Last()
Dim lrow As Long

For lrow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Cells(lrow, "B") = Cells(lrow, "B").Offset(-1, 0) Then
Cells(lrow, "B").Offset(-1, 0).EntireRow.Delete
End If

Next lrow
End Sub
[/pre]
But it is considering Column B only it should consider column H also.


Can you any one help on this.


Regards,

Satish.
 
When it considers column H, is that an AND condition or an OR condition? Ie, delete row if BOTH col B and col H have duplicates, or delete row if col B or col H have a duplicate?
 
Yes, but since you didn't say which way is the correct one, I'll just guess.

[pre]
Code:
Sub Row_Dupe_Killer_Keep_Last()
Dim lrow As Long

For lrow = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1

'I'm guessing you wanted an AND condition
If Cells(lrow, "B") = Cells(lrow, "B").Offset(-1, 0) And _
Cells(lrow, "H") = Cells(lrow, "H").Offset(-1, 0) Then

Cells(lrow, "B").Offset(-1, 0).EntireRow.Delete
End If

Next lrow
End Sub
[/pre]
 
Back
Top