Removing rows with ALMOST duplicate entries BUT

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I have a sheet with multiple rows and 5 columns:

A...... B......C......D.....E
DATA MB02 7.25 305 X (remove)<remove<remove< font="">
DATA MB02 9.45 305 X (remove)
<remove< font=""> <remove
DATA MB02 20.00 305 X
DATA MB02 15.00 250 X<remove <remove<="" font=""> (remove)
DATA MB02 27.00 250 X
DATA MB02 40.00 150 X
DATA MB03 7.25 305 X

I need to remove the rows with duplicates in column B & D (305 & 250) BUT leave the row with the largest entry in column C (20.00 & 27.00)

I can remove identical rows using:

Code:
Dim MyRange As Range
lastrow = Sheets("DataSheet").Range("A" & Rows.Count).End(xlUp).Row
Set MyRange = Sheets("DataSheet").Range("A1:E" & lastrow)
'remove duplicate rows if filename matches
MyRange.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5)

but I don't know how to the same with looking just at column B and D (both the same) and largest value in column C

If you can point me in the right direction, I'd be most grateful

Thanks</remove></remove
</remove<></remove<remove<>
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Jun14
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Delrng [COLOR="Navy"]As[/COLOR] Range, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    txt = Dn.Value & Dn.Offset(, 2).Value
    [COLOR="Navy"]If[/COLOR] Not .Exists(txt) [COLOR="Navy"]Then[/COLOR]
        .Add txt, Dn.Offset(, 1)
    [COLOR="Navy"]Else[/COLOR]
       [COLOR="Navy"]If[/COLOR] .Item(txt) >= Dn.Offset(, 1) [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn.Offset(, 1) Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn.Offset(, 1))
       [COLOR="Navy"]ElseIf[/COLOR] Dn.Offset(, 1).Value >= .Item(txt) [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = .Item(txt) Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, .Item(txt))
           [COLOR="Navy"]Set[/COLOR] .Item(txt) = Dn.Offset(, 1)
       [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Mick, once again you come up trumps mate!

I added a final 'End With' after the last 'Next' statement, but it does exactly what I need it to do!

Thanks again buddy!

Rob
 
Upvote 0
Just a quick one Mick,

Will this only work with numbers that are in columns C & D?

I have a similar page to sort, but in column D, the value is a mix of letters and numbers... or just letters?

ie:

A...... B......C......D.....E
DATA MB02 7.25 CP305 X (remove)<remove<remove< font="" style="color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">
DATA MB02 9.45 CP305 X (remove)
<remove< font=""><remove
DATA MB02 20.00 CP305 X
DATA MB02 15.00 CP250 X<remove <remove<="" font=""> (remove)
DATA MB02 27.00 CP250 X
DATA MB02 40.00 CP150 X
DATA MB03 7.25 CP305 X</remove></remove
</remove<></remove<remove<>
 
Last edited:
Upvote 0
Thanks Mick!

This will come in very handy for me!

Rob
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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