Find the sum of values against names and list in order of top to bottom. Preferrabally top 5

JOHN007

New Member
Joined
Aug 7, 2014
Messages
38
Let us say i have list of students and score against each student. (Name of student may\may not repeat. i the list of top 3 students(Rank) and sum of scores against each student.


Input:
[TABLE="width: 596"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Shash[/TD]
[TD="align: center"]40[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]Yog[/TD]
[TD="align: center"]10[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]Yog[/TD]
[TD="align: center"]10[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]Avi[/TD]
[TD="align: center"]10[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]Ran[/TD]
[TD="align: center"]80[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]Shash[/TD]
[TD="align: center"]50[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]Raj[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: center"]Raj[/TD]
[TD="align: center"]2[/TD]
[/TR]
</tbody>[/TABLE]


Output:
Result must be



[TABLE="width: 557"]
<tbody>[TR]
[TD][/TD]
[TD]Name[/TD]
[TD]Top 3 total scores[/TD]
[/TR]
[TR]
[TD]Rank 1[/TD]
[TD]Shash[/TD]
[TD]90[/TD]
[/TR]
[TR]
[TD]Rank 2[/TD]
[TD]Ran[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]Rank 3[/TD]
[TD]Yog[/TD]
[TD]20[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this for results starting "D1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG16May04
[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] nstr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), 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(, 1).Value
        [COLOR="Navy"]Else[/COLOR]
            .Item(Dn.Value) = .Item(Dn.Value) + Dn.Offset(, 1).Value
         [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR]
    Range("D1:F1").Value = Array("Rank", "Name", "Score")
  [COLOR="Navy"]Dim[/COLOR] Nam [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] t
    [COLOR="Navy"]For[/COLOR] n = 1 To 3
        num = Application.Large(.items(), n)
        c = c + 1
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
            t = .Item(K)
            [COLOR="Navy"]If[/COLOR] .Item(K) = num [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]If[/COLOR] Not InStr(nstr, K) > 0 [COLOR="Navy"]Then[/COLOR]
                    nstr = nstr & "," & K
                    Nam = K
                    [COLOR="Navy"]Exit[/COLOR] For
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] K
            Cells(c + 1, "D") = "Rank" & c
            Cells(c + 1, "E") = Nam
            Cells(c + 1, "F") = num
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
I've just noticed you want the top 5, Change line below as shown in Red.
Code:
For n = 1 To[SIZE=3] [COLOR=#ff0000][B]5[/B][/COLOR][/SIZE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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