Identifying the highest value for multiple records.

gseft

New Member
Joined
Jul 5, 2018
Messages
7
Hello everyone,

I expect this will be something that is very simple, but I am in a pinch and need a resolution to this without me researching. I have a file in column A (ID) I have an account code and each account has multiple ratings Column D. I want to quickly find and select the rows that have the highest value in column D. Some ratings may be duplicated for the account i.e. account 234 may have 4 records with a rating of 8.

Thanks

[TABLE="width: 148"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]ID[/TD]
[TD]Rating[/TD]
[/TR]
[TR]
[TD]00000000514[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000000514[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000000514[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]00000000735[/TD]
[TD="align: right"]9[/TD]
[/TR]
[TR]
[TD]00000000735[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000000735[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000000735[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000000735[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]00000000927[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]00000000927[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]00000001563[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001732[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]00000001834[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]00000002074[/TD]
[TD="align: right"]9[/TD]
[/TR]
[TR]
[TD]00000002074[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD]00000002124[/TD]
[TD="align: right"]8[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Are you looking for a formula or VBA?
Also what happens when the account has multiple rows with the max rating?
 
Upvote 0
Fluff,

I don't have a preference, I will have multiple files like this that I will need to clean. So whatever is easiest to modify.

If the account has multiple rows at the max rating I want one record.

Thanks
 
Upvote 0
Let me also clarify after reading my post this also may be confusing. I want the highest value for each account. So, some accounts will only have a rating of 5 although the highest is 9.
 
Upvote 0
If you want to delete all but one row with the highest rank
Sort the data on ID then on Rating(highest to lowest)
You can then use remove duplicates select the entire data & make sure that only the ID column is checked.
 
Upvote 0
Yup, it will keep the first of each duplicate.
 
Upvote 0
Another option
Max value for each account retained , other rows deleted !!
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Mar17
[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]
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", Range("A" & 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
    [COLOR="Navy"]If[/COLOR] Not .exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        .Add Dn.Value, Dn.Offset(, 3)
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]If[/COLOR] Dn.Offset(, 3).Value > .Item(Dn.Value) [COLOR="Navy"]Then[/COLOR]
           [COLOR="Navy"]Set[/COLOR] .Item(Dn.Value) = Dn.Offset(, 3)
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]Dim[/COLOR] k [COLOR="Navy"]As[/COLOR] Variant, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
  [COLOR="Navy"]If[/COLOR] Not Dn.Offset(, 3).Address = .Item(Dn.Value).Address [COLOR="Navy"]Then[/COLOR]
      [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
   [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
 [COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] With

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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