Remove highest rows of duplicate data

MuppetReaper

New Member
Joined
Jun 14, 2013
Messages
30
I'm running a process that imports data into a excel table and this can be done multiple times, so I want a way to remove the older instances and only keep the newest, which would be furthest down the table.
When I've tried using the remove dupes function it always removes the bottom values, is there a way in VBA to force it to remove the older entries?
I'm basing the dupes in values in columns A and C
thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
This is perfectly possible. A couple of questions
Do you want to delete the entire row for duplicates?
Do both col A & col C have to match to be considered a duplicate? (ie any row that has both Muppet in col A And Reaper in col C)
 
Upvote 0
Hi, yes, I need to delete the entire row and yes, both columns need to match (A is date and C is a ref no.)
thanks
 
Upvote 0
Ok, how about
Code:
Sub DeleteDupes()

   Dim Rng As Range
   Dim Cnt As Long
   Dim Valu As String
   
   With CreateObject("scripting.dictionary")
      For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
         Valu = Range("A" & Cnt).Value & Range("C" & Cnt).Value
         If Not .exists(Valu) Then
            .Add Valu, Nothing
         ElseIf Rng Is Nothing Then
            Set Rng = Range("A" & Cnt)
         Else
            Set Rng = Union(Rng, Range("A" & Cnt))
         End If
      Next Cnt
   End With
   Rng.EntireRow.[COLOR=#0000ff]Interior.Color = 230[/COLOR]
   
End Sub
Initially this will simply put a background fill on the rows to be deleted. If it's ok then change the part in blue & replace with .Delete
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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