Max Value from long range of date based on unique key

MarcMermans

New Member
Joined
Dec 4, 2012
Messages
7
Hello,


I need some help from the experts on this forum.

As seen in the next example i need to known the line with the highest value for the keycode, in this example i have marked the row with an *.
The keycode can exist once ore more than once and the complete list is around 60 000 rows. This is not a one time solution because i want to use this function regulary.

Is i't possible to write a VBA for this.



KEYCODEValue 1Value 2Value 3Value 4
230069021266235114
230069021128186493*
230069021143111067
2300690219910110255
230069021111692113
2300690216934778
2300690214748735
2300690212581272
230011211392912736
2300112119012474117*
230011211454116100
23001121142795983
230011211571079823
2300112111128410624
23001121150829171
23001121116761921
230011211281099478
23002295460535433
230022954121104807
2300229541186612611*
2300229546815108120
230013270871312222*
23001327049511770
230013270651038540
23001327063524144
2300132703712043
230020079381159588*
23002007946305610
23002008027963119*
23002012325758697
2300201231231258189*
23002012310532961

<colgroup><col><col><col span="4"><col></colgroup><tbody>
</tbody>

<colgroup><col><col><col span="4"><col></colgroup><tbody></tbody>

<colgroup><col><col span="4"><col></colgroup><tbody>
</tbody>


Thanks in advance.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this for Double "**" in column "G".
Code:
[COLOR="Navy"]Sub[/COLOR] MG14Dec06
[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] Dic [COLOR="Navy"]As[/COLOR] Object
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] Not Dic.Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        Dic.Add Dn.Value, Dn
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]If[/COLOR] Application.Max(Dn.Offset(, 2).Resize(, 4)) > _
        Application.Max(Dic(Dn.Value).Offset(, 2).Resize(, 4)) [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] Dic(Dn.Value) = Dn
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]Dim[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic.keys
    Dic(K).Offset(, 6) = "**"
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi Mick,

It looks like your code is indeed picking all Max numbers ... with the exception of the very key ...
What is the reason ???
 
Upvote 0
I'm Not sure I understand your point !!!
My understanding of the question is:- The Unique "Keys" columns is there to separate the sets of numbers, so that the max row marked represents the row with max value, for each set of numbers (not including the key number) with the same "Key" value
 
Upvote 0
For the first Keycode 230069021, the Max is located in cell B3 ... whereas the macro indicates row 2 ...
 
Upvote 0
Max for 230069021= 128 shown below, as result from code on row (3) :-

KEYCODEValue 1Value 2Value 3Value 4
230069021266235114
230069021128186493**
230069021143111067
2300690219910110255
230069021111692113
2300690216934778
2300690214748735
2300690212581272

<tbody>
</tbody>
 
Upvote 0
Mick ... you are right ...

At my end, the macro marks row 2 ... as if 114 was the max ???
 
Upvote 0
I think the reason is:_
When I paste the data on my sheet, column "B" is Blank and the numbers run from columns "C to F", so if your data start in column "B" then the code will miss that and start on column "C".
Good shout though !!!!
 
Upvote 0
Thanks a lot for the explanation ... !!! since I was quite disturbed ... :)
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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