Excel Remove Duplicate

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?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You can easily enough do it with VBA code.

Is that the sort of approach you're looking for?

If they're duplicates, does it matter which one you keep, other than sheet location, or perhaps formatting?
 
Upvote 0
Hi, im want to do it with vba. My approach is to keep the last record of duplicate from searching from Column B. Any1 can help?
 
Upvote 0
How about this...

Assumes you have a header on column B

Code:
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
 
Upvote 0
Yes I just realized I got it backwards. Give me a minute.

Will there be more than one duplicate and is the list sorted?
 
Upvote 0
Well just to be safe let's go with this

Code:
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

Sort the list and then run. I need be we can build the sort into the code.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top