Removing Dupes

JTL9161

Well-known Member
Joined
Aug 29, 2012
Messages
567
Office Version
  1. 365
Platform
  1. Windows
I have a list of names and numbers that i trying to remove a duplicate but keeping the one with the higher value. The names are coming from another listing so each entry is =UPPER(A166)

AAA10XXX9
BBB9ZZZ9
XXX9AAA10
DDD6PPP7
WWW5YYY10
PPP7DDD6
TTT5CCC9
YYY10WWW5
ZZZ9BBB9
CCC9TTT5

There are 2 similar entries for each line but flipped. Example (AAA 10 XXX 9) and (XXX 9 AAA 10). I am looking to eliminate the duplicate and keep the entry with the lower number (if possible) From the listed example
(AAA 10 XXX 9) and (XXX 9 AAA 10) I am loooking to keep the 2nd one (XXX 9 AAA 10) because of the 9 for XXX. After removing the not needed entry I am looking to consolidate the listing down to 5 lines. If both have thes ame numbers (BBB 9 ZZZ 9 & ZZZ 9 BBB 9) I just need 1 of the listing (either one) to stay and not show the other. Hope I explained what I am looking for well enough.

Thank you,
Jamie
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi @JTL9161, thanks for posting on the forum!

The following macro assumes that the data starts at cell A1, if it doesn't, some changes would have to be made to the macro.
It would be more complicated for us to try to make the macros dynamic. In the future, please indicate where your data starts, use the XL2BB tool to put up a minisheet and help us help you.
It also uses column "E" as a helper, if you are using column "E", change the "E" in the code to a column you have available.

So try the following on a copy of your sheet.
VBA Code:
Sub RemovingDups_v6()
  Dim c As Range, f As Range, rng As Range
  Dim lr As Long
  
  lr = Range("A" & Rows.Count).End(3).Row
  Set rng = Range("A" & lr + 1)
  
  For Each c In Range("A1", Range("A" & Rows.Count).End(3))
    If Range("E" & c.Row).Value = "" Then
      Set f = Range("C:C").Find(c.Value, , xlValues, xlWhole, , , False)
      Range("E" & f.Row).Value = "x"
      If Range("B" & c.Row).Value <= Range("B" & f.Row).Value Then _
        Set rng = Union(rng, f) Else Set rng = Union(rng, c)
    End If
  Next
  
  rng.EntireRow.Delete
  Columns("E").ClearContents
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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