VBA REMOVE DUPLICATES AND KEEP LAST ONE

duplaly

New Member
Joined
May 26, 2020
Messages
8
Office Version
  1. 2019
HI
I need help to solve my problem of duplicates based on Columns A & B and delete EntireRow keepping the last entry
The vba code should compare A & B and delete the entire row duplicates.
Many Thanks!


AB
1 juin 2020Rouge Montréal
1 juin 2020International
1 juin 2020Rouge / GEC Qc
1 juin 2020Ottawa Fluo "J"
1 juin 2020Fluo "J"
1 juin 2020Abitibi Fluo "J"
1 juin 2020Fluo "G" - G-555
1 juin 2020Fluo "G"- G-551
1 juin 2020Domestique
1 juin 2020GEC Montréal
3 juin 2020Rouge Montréal
3 juin 2020International
3 juin 2020Rouge / GEC Qc
3 juin 2020Ottawa Fluo "J"
3 juin 2020Fluo "J"
3 juin 2020Abitibi Fluo "J"
3 juin 2020Fluo "G" - G-555
3 juin 2020Fluo "G"- G-551
3 juin 2020Domestique
3 juin 2020GEC Montréal
9 juin 2020Rouge Montréal
9 juin 2020International
9 juin 2020Rouge / GEC Qc
9 juin 2020Ottawa Fluo "J"
9 juin 2020Fluo "J"
9 juin 2020Abitibi Fluo "J"
9 juin 2020Fluo "G" - G-555
9 juin 2020Fluo "G"- G-551
9 juin 2020Domestique
9 juin 2020GEC Montréal
10 juin 2020Rouge Montréal
10 juin 2020International
10 juin 2020Rouge / GEC Qc
10 juin 2020Ottawa Fluo "J"
10 juin 2020Fluo "J"
10 juin 2020Abitibi Fluo "J"
10 juin 2020Fluo "G" - G-555
10 juin 2020Fluo "G"- G-551
10 juin 2020Domestique
10 juin 2020GEC Montréal
1 juin 2020Rouge Montréal
1 juin 2020International
1 juin 2020Rouge / GEC Qc
1 juin 2020Ottawa Fluo "J"
1 juin 2020Fluo "J"
1 juin 2020Abitibi Fluo "J"
1 juin 2020Fluo "G" - G-555
1 juin 2020Fluo "G"- G-551
1 juin 2020Domestique
1 juin 2020GEC Montréal
10 juin 2020Rouge Montréal
10 juin 2020International
10 juin 2020Rouge / GEC Qc
10 juin 2020Ottawa Fluo "J"
10 juin 2020Fluo "J"
10 juin 2020Abitibi Fluo "J"
10 juin 2020Fluo "G" - G-555
10 juin 2020Fluo "G"- G-551
10 juin 2020Domestique
10 juin 2020GEC Montréal
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

VBA Code:
Sub Delete_Rows()
  Dim a As Variant, dic As Object, r As Range
  Dim lr As Long, i As Long
  
  lr = Range("A" & Rows.Count).End(3).Row
  a = Range("A1:B" & lr)
  Set r = Range("A" & lr + 1)
  Set dic = CreateObject("Scripting.Dictionary")
  
  For i = UBound(a, 1) To 1 Step -1
    If dic.exists(a(i, 1) & "|" & a(i, 2)) Then
      Set r = Union(r, Range("A" & i))
    End If
    dic(a(i, 1) & "|" & a(i, 2)) = Empty
  Next
  
  r.EntireRow.Delete
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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