Excelnoobisme
Board Regular
- Joined
- Nov 19, 2010
- Messages
- 128
Im trying to remove duplicate line but excel always kept the 1st record and delete other. Is there anyway i can keep the last record and delete all other?
Sub DelDups()
Dim LR As Long
Dim r As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
If Application.WorksheetFunction.CountIf(Range("B2:B" & r), Range("B" & r).Text) > 1 Then
Range("B" & r).EntireRow.Delete
End If
Next r
End Sub
Sub DelDup()
Dim LR As Long
For LR = Cells(Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Cells(LR, "B") = Cells(LR, "B").Offset(-1, 0) Then
Cells(LR, "B").Offset(-1, 0).EntireRow.Delete
End If
Next LR
End Sub