Set Lists

MrExcel

.
Builders Club Member
Joined
Feb 8, 2002
Messages
3,392
Office Version
  1. 365
Platform
  1. Windows
This is being posted on behalf of user Beaumont:

There must be a way to do this. I have a list of 350 students in sets called x1,x2..x7 and y1,y2..y7. Their names are in column A, sets in B and scores in C. I want Excel to take this info, without having to sort it, and give me fourteen rank ordered lists, one for each set, with scores in the left column and names in the right. These could begin in say cell e2 & f2 then a narrow one column gap to h2 and i2 or something.

This would be a great start. Even better would be if we could show how far ahead each student is ahead of the last, e.g if top student in x1 is 5% ahead of next student then this next student should appear 5 cells further down etc.

Best of all would be if we could do a quick visual comparison of the fourteen resultant lists (or perhaps the seven x sets, then the seven y sets) so that we can immediately see if anyone needs to be moved between groups.

Finally I would like someone to bring peace to the Middle East, land a human on Mars and enable my football team to win all their games next season.

Seriously I would appreciate any help you can give as I've been wrestling with this for years and have only achieved partial solutions. I could discuss these with you but don't want to prejudice any solutions you come up with.

Peter Beaumont
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Is a VBA solution acceptable?
Why not allow a sort?

The Mars and Middle East things might be possible, but it really depends what your team is.
 
Upvote 0
Howdy, let's see if this maxes out the character limit. :LOL:

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> Sort_by_Grp()
<SPAN style="color:green">' Kudos to John Walkenbach & J.G. Hussey related to Coll. Sort Technique _
    http://j-walk.com/ss/excel/tips/tip47.htm</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> cl <SPAN style="color:darkblue">As</SPAN> Range, cls <SPAN style="color:darkblue">As</SPAN> Range, ws <SPAN style="color:darkblue">As</SPAN> Worksheet
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, j <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> Swap1, Swap2

<SPAN style="color:darkblue">Dim</SPAN> x1 <SPAN style="color:darkblue">As</SPAN> Collection, x2 <SPAN style="color:darkblue">As</SPAN> Collection, x3 <SPAN style="color:darkblue">As</SPAN> Collection, x4 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> x5 <SPAN style="color:darkblue">As</SPAN> Collection, x6 <SPAN style="color:darkblue">As</SPAN> Collection, x7 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> y1 <SPAN style="color:darkblue">As</SPAN> Collection, y2 <SPAN style="color:darkblue">As</SPAN> Collection, y3 <SPAN style="color:darkblue">As</SPAN> Collection, y4 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> y5 <SPAN style="color:darkblue">As</SPAN> Collection, y6 <SPAN style="color:darkblue">As</SPAN> Collection, y7 <SPAN style="color:darkblue">As</SPAN> Collection

<SPAN style="color:darkblue">Set</SPAN> x1 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x2 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x3 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> x4 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x5 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x6 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> x7 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y1 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y2 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y3 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y4 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y5 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y6 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y7 = <SPAN style="color:darkblue">New</SPAN> Collection

<SPAN style="color:darkblue">Set</SPAN> cls = Sheets(1).[a1:a350]

<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> cls
    <SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> cl(, 2).Value
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x1"
            x1.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x2"
            x2.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x3"
            x3.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x4"
            x4.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x5"
            x5.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x6"
            x6.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x7"
            x7.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y1"
            y1.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y2"
            y2.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y3"
            y3.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y4"
            y4.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y5"
            y5.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y6"
            y6.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y7"
            y7.Add Array(cl(, 3), cl)
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Set</SPAN> cls = <SPAN style="color:darkblue">Nothing</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x1.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x1.Count
        <SPAN style="color:darkblue">If</SPAN> x1(i)(0) < x1(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x1(i)
            Swap2 = x1(j)
            x1.Add Swap1, before:=j
            x1.Add Swap2, before:=i
            x1.Remove i + 1
            x1.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x2.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x2.Count
        <SPAN style="color:darkblue">If</SPAN> x2(i)(0) < x2(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x2(i)
            Swap2 = x2(j)
            x2.Add Swap1, before:=j
            x2.Add Swap2, before:=i
            x2.Remove i + 1
            x2.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x3.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x3.Count
        <SPAN style="color:darkblue">If</SPAN> x3(i)(0) < x3(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x3(i)
            Swap2 = x3(j)
            x3.Add Swap1, before:=j
            x3.Add Swap2, before:=i
            x3.Remove i + 1
            x3.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x4.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x4.Count
        <SPAN style="color:darkblue">If</SPAN> x4(i)(0) < x4(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x4(i)
            Swap2 = x4(j)
            x4.Add Swap1, before:=j
            x4.Add Swap2, before:=i
            x4.Remove i + 1
            x4.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x5.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x5.Count
        <SPAN style="color:darkblue">If</SPAN> x5(i)(0) < x5(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x5(i)
            Swap2 = x5(j)
            x5.Add Swap1, before:=j
            x5.Add Swap2, before:=i
            x5.Remove i + 1
            x5.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x6.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x6.Count
        <SPAN style="color:darkblue">If</SPAN> x6(i)(0) < x6(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x6(i)
            Swap2 = x6(j)
            x6.Add Swap1, before:=j
            x6.Add Swap2, before:=i
            x6.Remove i + 1
            x6.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x7.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x7.Count
        <SPAN style="color:darkblue">If</SPAN> x7(i)(0) < x7(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x7(i)
            Swap2 = x7(j)
            x7.Add Swap1, before:=j
            x7.Add Swap2, before:=i
            x7.Remove i + 1
            x7.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y1.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y1.Count
        <SPAN style="color:darkblue">If</SPAN> y1(i)(0) < y1(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y1(i)
            Swap2 = y1(j)
            y1.Add Swap1, before:=j
            y1.Add Swap2, before:=i
            y1.Remove i + 1
            y1.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y2.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y2.Count
        <SPAN style="color:darkblue">If</SPAN> y2(i)(0) < y2(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y2(i)
            Swap2 = y2(j)
            y2.Add Swap1, before:=j
            y2.Add Swap2, before:=i
            y2.Remove i + 1
            y2.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y3.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y3.Count
        <SPAN style="color:darkblue">If</SPAN> y3(i)(0) < y3(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y3(i)
            Swap2 = y3(j)
            y3.Add Swap1, before:=j
            y3.Add Swap2, before:=i
            y3.Remove i + 1
            y3.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y4.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y4.Count
        <SPAN style="color:darkblue">If</SPAN> y4(i)(0) < y4(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y4(i)
            Swap2 = y4(j)
            y4.Add Swap1, before:=j
            y4.Add Swap2, before:=i
            y4.Remove i + 1
            y4.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y5.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y5.Count
        <SPAN style="color:darkblue">If</SPAN> y5(i)(0) < y5(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y5(i)
            Swap2 = y5(j)
            y5.Add Swap1, before:=j
            y5.Add Swap2, before:=i
            y5.Remove i + 1
            y5.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y6.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y6.Count
        <SPAN style="color:darkblue">If</SPAN> y6(i)(0) < y6(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y6(i)
            Swap2 = y6(j)
            y6.Add Swap1, before:=j
            y6.Add Swap2, before:=i
            y6.Remove i + 1
            y6.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y7.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y7.Count
        <SPAN style="color:darkblue">If</SPAN> y7(i)(0) < y7(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y7(i)
            Swap2 = y7(j)
            y7.Add Swap1, before:=j
            y7.Add Swap2, before:=i
            y7.Remove i + 1
            y7.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

Application.ScreenUpdating = <SPAN style="color:darkblue">False</SPAN>

<SPAN style="color:darkblue">Set</SPAN> ws = Sheets(2)
ws.[e:h].ClearContents
<SPAN style="color:darkblue">With</SPAN> ws.[e1:h1]
    .Value = [{"Group","Score","","Name"}]
    .HorizontalAlignment = xlCenter
    .Font.Bold = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x1.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x1"
    cl = x1(i)(0): cl(, 3) = x1(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x2.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x2"
    cl = x2(i)(0): cl(, 3) = x2(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x3.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x3"
    cl = x3(i)(0): cl(, 3) = x3(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x4.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x4"
    cl = x4(i)(0): cl(, 3) = x4(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x5.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x5"
    cl = x5(i)(0): cl(, 3) = x5(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x6.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x6"
    cl = x6(i)(0): cl(, 3) = x6(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x7.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x7"
    cl = x7(i)(0): cl(, 3) = x7(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y1.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y1"
    cl = y1(i)(0): cl(, 3) = y1(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y2.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y2"
    cl = y2(i)(0): cl(, 3) = y2(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y3.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y3"
    cl = y3(i)(0): cl(, 3) = y3(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y4.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y4"
    cl = y4(i)(0): cl(, 3) = y4(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y5.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y5"
    cl = y5(i)(0): cl(, 3) = y5(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y6.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y6"
    cl = y6(i)(0): cl(, 3) = y6(i)(1)
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y7.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y7"
    cl = y7(i)(0): cl(, 3) = y7(i)(1)
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Set</SPAN> cl = <SPAN style="color:darkblue">Nothing</SPAN>
ws.Columns("G:G").ColumnWidth = 3.29
<SPAN style="color:darkblue">Set</SPAN> ws = <SPAN style="color:darkblue">Nothing</SPAN>

Application.ScreenUpdating = <SPAN style="color:darkblue">True</SPAN>

<SPAN style="color:darkblue">Set</SPAN> x1 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x2 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x3 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x4 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">Set</SPAN> x5 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x6 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x7 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y1 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">Set</SPAN> y2 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y3 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y4 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y5 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">Set</SPAN> y6 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y7 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
</FONT>

Good, it didn't. Assumed data in sheets(1) [a1:c150]. Stacked 14 collections, sorted them. Slammed the results into sheets(2) [e2:g351] with headers. At this point you can work with individual collections.

Hope a vba approach is okay. :LOL: Might not be the best method, but it seemed to work on my spot checking. Didn't follow:
Best of all would be if we could do a quick visual comparison of the fourteen resultant lists (or perhaps the seven x sets, then the seven y sets) so that we can immediately see if anyone needs to be moved between groups.

Some sort of deviation calc. from the overall mean perhaps? Different means/outliers per group? Should be fairly doable at this point.

In any case, hope this helps.
 
Upvote 0
Solution
Don't know why Nate suggested a VBA solution. From the problem description, and with the exception of some formatting requirements, I believe a PivotTable should do the job.

And, I guess the comment about visual comparison of the sets is in the same league as winning teams, since if we could get XL to understand sight...

MrExcel said:
This is being posted on behalf of user Beaumont:

There must be a way to do this. I have a list of 350 students in sets called x1,x2..x7 and y1,y2..y7. Their names are in column A, sets in B and scores in C. I want Excel to take this info, without having to sort it, and give me fourteen rank ordered lists, one for each set, with scores in the left column and names in the right. These could begin in say cell e2 & f2 then a narrow one column gap to h2 and i2 or something.

This would be a great start. Even better would be if we could show how far ahead each student is ahead of the last, e.g if top student in x1 is 5% ahead of next student then this next student should appear 5 cells further down etc.

Best of all would be if we could do a quick visual comparison of the fourteen resultant lists (or perhaps the seven x sets, then the seven y sets) so that we can immediately see if anyone needs to be moved between groups.

Finally I would like someone to bring peace to the Middle East, land a human on Mars and enable my football team to win all their games next season.

Seriously I would appreciate any help you can give as I've been wrestling with this for years and have only achieved partial solutions. I could discuss these with you but don't want to prejudice any solutions you come up with.

Peter Beaumont
 
Upvote 0
I reckon I can manage the visual comparison bit myself.

Thank you for all your help. I have been unable to post from my home computer. I hope this one will work.

I am willing to use a VBA solution if necessary (did you really write all that code in such a short time?!) but I am unlikely to be able to adapt it to other slightly different situations. The code written seemed to do the first part of the task very well.

I am intrigued by the pivot table solution and would like to hear more.

Thanks again
Pete
 
Upvote 0
Hello again,
Tusharm said:
Don't know why Nate suggested a VBA solution.

I know, it's only vba, but I like it. :LOL: Seriously, it's effective, meaning accurate and returns the data in a flexible/preferred format (with the right code modifications) and won't alter your file size to much extent. Very functional, not too slow, seems very viable to me.

Beaumont said:
I am willing to use a VBA solution if necessary (did you really write all that code in such a short time?!) but I am unlikely to be able to adapt it to other slightly different situations. The code written seemed to do the first part of the task very well.

Nope, I used the recorder. :LOL: Well, keep this is as a last resort. :LOL: I guess one man's trash is another man's treasure... To each their reach. :LOL:

Yeah, I missed the other part, and rereading it, I realize that I don't understand this:

This would be a great start. Even better would be if we could show how far ahead each student is ahead of the last, e.g if top student in x1 is 5% ahead of next student then this next student should appear 5 cells further down etc.

I've adjusted the code to populate column I with the percentage of each students score above that of the lowest scoring student in the group. The spacing thing threw me off, why would you want to correlate a percentage difference with actual cell spacing? In any case, here's the tweak:

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> Sort_by_Grp2()
<SPAN style="color:green">' Kudos to John Walkenbach & J.G. Hussey from Coll. Sort Technique _
    http://j-walk.com/ss/excel/tips/tip47.htm</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> cl <SPAN style="color:darkblue">As</SPAN> Range, cls <SPAN style="color:darkblue">As</SPAN> Range, ws <SPAN style="color:darkblue">As</SPAN> Worksheet
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, j <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> Swap1, Swap2

<SPAN style="color:darkblue">Dim</SPAN> x1 <SPAN style="color:darkblue">As</SPAN> Collection, x2 <SPAN style="color:darkblue">As</SPAN> Collection, x3 <SPAN style="color:darkblue">As</SPAN> Collection, x4 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> x5 <SPAN style="color:darkblue">As</SPAN> Collection, x6 <SPAN style="color:darkblue">As</SPAN> Collection, x7 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> y1 <SPAN style="color:darkblue">As</SPAN> Collection, y2 <SPAN style="color:darkblue">As</SPAN> Collection, y3 <SPAN style="color:darkblue">As</SPAN> Collection, y4 <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Dim</SPAN> y5 <SPAN style="color:darkblue">As</SPAN> Collection, y6 <SPAN style="color:darkblue">As</SPAN> Collection, y7 <SPAN style="color:darkblue">As</SPAN> Collection

<SPAN style="color:darkblue">Set</SPAN> x1 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x2 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x3 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> x4 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x5 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> x6 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> x7 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y1 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y2 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y3 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y4 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y5 = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> y6 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> y7 = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'****************************</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> cls = Sheets(1).[a1:a350] <SPAN style="color:green">'Set Your Input Range</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'****************************</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> cls
    <SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> cl(, 2).Value
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x1"
            x1.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x2"
            x2.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x3"
            x3.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x4"
            x4.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x5"
            x5.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x6"
            x6.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "x7"
            x7.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y1"
            y1.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y2"
            y2.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y3"
            y3.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y4"
            y4.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y5"
            y5.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y6"
            y6.Add Array(cl(, 3), cl)
        <SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Is</SPAN> = "y7"
            y7.Add Array(cl(, 3), cl)
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Set</SPAN> cls = <SPAN style="color:darkblue">Nothing</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x1.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x1.Count
        <SPAN style="color:darkblue">If</SPAN> x1(i)(0) < x1(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x1(i)
            Swap2 = x1(j)
            x1.Add Swap1, before:=j
            x1.Add Swap2, before:=i
            x1.Remove i + 1
            x1.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x2.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x2.Count
        <SPAN style="color:darkblue">If</SPAN> x2(i)(0) < x2(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x2(i)
            Swap2 = x2(j)
            x2.Add Swap1, before:=j
            x2.Add Swap2, before:=i
            x2.Remove i + 1
            x2.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x3.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x3.Count
        <SPAN style="color:darkblue">If</SPAN> x3(i)(0) < x3(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x3(i)
            Swap2 = x3(j)
            x3.Add Swap1, before:=j
            x3.Add Swap2, before:=i
            x3.Remove i + 1
            x3.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x4.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x4.Count
        <SPAN style="color:darkblue">If</SPAN> x4(i)(0) < x4(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x4(i)
            Swap2 = x4(j)
            x4.Add Swap1, before:=j
            x4.Add Swap2, before:=i
            x4.Remove i + 1
            x4.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x5.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x5.Count
        <SPAN style="color:darkblue">If</SPAN> x5(i)(0) < x5(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x5(i)
            Swap2 = x5(j)
            x5.Add Swap1, before:=j
            x5.Add Swap2, before:=i
            x5.Remove i + 1
            x5.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x6.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x6.Count
        <SPAN style="color:darkblue">If</SPAN> x6(i)(0) < x6(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x6(i)
            Swap2 = x6(j)
            x6.Add Swap1, before:=j
            x6.Add Swap2, before:=i
            x6.Remove i + 1
            x6.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x7.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> x7.Count
        <SPAN style="color:darkblue">If</SPAN> x7(i)(0) < x7(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = x7(i)
            Swap2 = x7(j)
            x7.Add Swap1, before:=j
            x7.Add Swap2, before:=i
            x7.Remove i + 1
            x7.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y1.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y1.Count
        <SPAN style="color:darkblue">If</SPAN> y1(i)(0) < y1(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y1(i)
            Swap2 = y1(j)
            y1.Add Swap1, before:=j
            y1.Add Swap2, before:=i
            y1.Remove i + 1
            y1.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y2.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y2.Count
        <SPAN style="color:darkblue">If</SPAN> y2(i)(0) < y2(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y2(i)
            Swap2 = y2(j)
            y2.Add Swap1, before:=j
            y2.Add Swap2, before:=i
            y2.Remove i + 1
            y2.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y3.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y3.Count
        <SPAN style="color:darkblue">If</SPAN> y3(i)(0) < y3(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y3(i)
            Swap2 = y3(j)
            y3.Add Swap1, before:=j
            y3.Add Swap2, before:=i
            y3.Remove i + 1
            y3.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y4.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y4.Count
        <SPAN style="color:darkblue">If</SPAN> y4(i)(0) < y4(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y4(i)
            Swap2 = y4(j)
            y4.Add Swap1, before:=j
            y4.Add Swap2, before:=i
            y4.Remove i + 1
            y4.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y5.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y5.Count
        <SPAN style="color:darkblue">If</SPAN> y5(i)(0) < y5(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y5(i)
            Swap2 = y5(j)
            y5.Add Swap1, before:=j
            y5.Add Swap2, before:=i
            y5.Remove i + 1
            y5.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y6.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y6.Count
        <SPAN style="color:darkblue">If</SPAN> y6(i)(0) < y6(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y6(i)
            Swap2 = y6(j)
            y6.Add Swap1, before:=j
            y6.Add Swap2, before:=i
            y6.Remove i + 1
            y6.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y7.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> y7.Count
        <SPAN style="color:darkblue">If</SPAN> y7(i)(0) < y7(j)(0) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = y7(i)
            Swap2 = y7(j)
            y7.Add Swap1, before:=j
            y7.Add Swap2, before:=i
            y7.Remove i + 1
            y7.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

Application.ScreenUpdating = <SPAN style="color:darkblue">False</SPAN>

<SPAN style="color:darkblue">Set</SPAN> ws = Sheets(2)
ws.[e:i].ClearContents
<SPAN style="color:darkblue">With</SPAN> ws.[e1:i1]
    .Value = [{"Group","Score","","Name","% Above Last"}] <SPAN style="color:green">'Set Your Headers</SPAN>
    .HorizontalAlignment = xlCenter
    .Font.Bold = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x1.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x1"    <SPAN style="color:green">'Pabel group on first</SPAN>
    cl = x1(i)(0): cl(, 3) = x1(i)(1) <SPAN style="color:green">'Plant Score & Name</SPAN>
    cl(, 4) = x1(i)(0) / x1(x1.Count)(0) - 1 <SPAN style="color:green">'Plant % Above Last</SPAN>
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x2.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x2"
    cl = x2(i)(0): cl(, 3) = x2(i)(1)
    cl(, 4) = x2(i)(0) / x2(x2.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x3.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x3"
    cl = x3(i)(0): cl(, 3) = x3(i)(1)
    cl(, 4) = x3(i)(0) / x3(x3.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x4.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x4"
    cl = x4(i)(0): cl(, 3) = x4(i)(1)
    cl(, 4) = x4(i)(0) / x4(x4.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x5.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x5"
    cl = x5(i)(0): cl(, 3) = x5(i)(1)
    cl(, 4) = x5(i)(0) / x5(x5.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x6.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x6"
    cl = x6(i)(0): cl(, 3) = x6(i)(1)
    cl(, 4) = x6(i)(0) / x6(x6.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> x7.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "x7"
    cl = x7(i)(0): cl(, 3) = x7(i)(1)
    cl(, 4) = x7(i)(0) / x7(x7.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y1.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y1"
    cl = y1(i)(0): cl(, 3) = y1(i)(1)
    cl(, 4) = y1(i)(0) / y1(y1.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y2.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y2"
    cl = y2(i)(0): cl(, 3) = y2(i)(1)
    cl(, 4) = y2(i)(0) / y2(y2.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y3.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y3"
    cl = y3(i)(0): cl(, 3) = y3(i)(1)
    cl(, 4) = y3(i)(0) / y3(y3.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y4.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y4"
    cl = y4(i)(0): cl(, 3) = y4(i)(1)
    cl(, 4) = y4(i)(0) / y4(y4.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y5.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y5"
    cl = y5(i)(0): cl(, 3) = y5(i)(1)
    cl(, 4) = y5(i)(0) / y5(y5.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y6.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y6"
    cl = y6(i)(0): cl(, 3) = y6(i)(1)
    cl(, 4) = y6(i)(0) / y6(y6.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> y7.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = "y7"
    cl = y7(i)(0): cl(, 3) = y7(i)(1)
    cl(, 4) = y7(i)(0) / y7(y7.Count)(0) - 1
<SPAN style="color:darkblue">Next</SPAN>
ws.Range([i2], cl(, 4)).NumberFormat = "0.00%"
<SPAN style="color:darkblue">Set</SPAN> cl = <SPAN style="color:darkblue">Nothing</SPAN>
ws.[g:g].ColumnWidth = 3
ws.[e:f,h:i].EntireColumn.AutoFit
<SPAN style="color:darkblue">Set</SPAN> ws = <SPAN style="color:darkblue">Nothing</SPAN>

Application.ScreenUpdating = <SPAN style="color:darkblue">True</SPAN>

<SPAN style="color:darkblue">Set</SPAN> x1 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x2 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x3 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x4 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">Set</SPAN> x5 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x6 = Nothing: <SPAN style="color:darkblue">Set</SPAN> x7 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y1 = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">Set</SPAN> y2 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y3 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y4 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y5 = <SPAN style="color:darkblue">Nothing</SPAN></FONT>
<font face=Courier New><SPAN style="color:darkblue">Set</SPAN> y6 = Nothing: <SPAN style="color:darkblue">Set</SPAN> y7 = <SPAN style="color:darkblue">Nothing</SPAN></FONT>
<font face=Courier New><SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>


This code is relatively flexible, you can change length of the list, vary group sizes, memborships and it should still fire. Have a good one eh.
 
Upvote 0
{shrug} Never did like reinventing the wheel, Nate. Da Vinci's take on simplicity and sophistication has had a major impact on my thinking for a rather long time.
NateO said:
Hello again,
Tusharm said:
Don't know why Nate suggested a VBA solution.

I know, it's only vba, but I like it. :LOL: Seriously, it's effective, meaning accurate and returns the data in a flexible/preferred format (with the right code modifications) and won't alter your file size to much extent. Very functional, not too slow, seems very viable to me.
 
Upvote 0
Although the code posted is interesting, I agree with Tusharm. This problem is being over complicated. A well designed PIVOT TABLE should yield the correct results
 
Upvote 0
lenze said:
Although the code posted is interesting,

Glad that you think so, a lot of people would not find this to be the case. More importantly, in my opinion, it's a relevant functioning solution to the problem.

I agree with Tusharm.

Polls are typically conducted in the lounge. :LOL:

This problem is being over complicated.

I agree. The complicated solution is matching the complications created by, as Mark was alluding to, confusing constraints. In which Excel version can someone not sort data? Turns out I also think the P.T. is overkill here as well. Here's another solution (which violates a constraint):

Copy the data to a new worksheet. Paste it in column a:c. Sort the data, Sort group in ascending order and score in descending. Now run some straight-forward worksheet functions through column d. Done.

A well designed PIVOT TABLE should yield the correct results

Fair enough. Peter has already stated interest in your alluded-to solution AND that he does not know how to set it up. Why not be a sport and help him out (versus responding to me (I already have a sufficient handle on the situation))? There's no need for me solve this a third or fourth way.

For all you KISS fans, stop reading here. I've streamlined the code above in terms of length:

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> Sort_by_Grp3()
<SPAN style="color:green">' Kudos to John Walkenbach & J.G. Hussey from Coll. Sort Technique _
    http://j-walk.com/ss/excel/tips/tip47.htm</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> cl <SPAN style="color:darkblue">As</SPAN> Range, cls <SPAN style="color:darkblue">As</SPAN> Range, ws <SPAN style="color:darkblue">As</SPAN> Worksheet
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, j <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> Swap1, Swap2
<SPAN style="color:darkblue">Dim</SPAN> MyCol <SPAN style="color:darkblue">As</SPAN> Collection, Cnt <SPAN style="color:darkblue">As</SPAN> Collection
<SPAN style="color:darkblue">Set</SPAN> MyCol = <SPAN style="color:darkblue">New</SPAN> Collection: <SPAN style="color:darkblue">Set</SPAN> Cnt = <SPAN style="color:darkblue">New</SPAN> Collection
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'****************************</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">Set</SPAN> cls = Sheets(1).[a1:a350] <SPAN style="color:green">'Set Your Input Range</SPAN>
<SPAN style="color:green"><SPAN style="color:green"><SPAN style="color:green">'****************************</SPAN></SPAN></SPAN>
<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> cls
    MyCol.Add Array(cl(, 3), cl, cl(, 2))
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Set</SPAN> cls = <SPAN style="color:darkblue">Nothing</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> MyCol.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> MyCol.Count
        <SPAN style="color:darkblue">If</SPAN> MyCol(i)(2) > MyCol(j)(2) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = MyCol(i)
            Swap2 = MyCol(j)
            MyCol.Add Swap1, before:=j
            MyCol.Add Swap2, before:=i
            MyCol.Remove i + 1
            MyCol.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> MyCol.Count - 1
    <SPAN style="color:darkblue">For</SPAN> j = i + 1 <SPAN style="color:darkblue">To</SPAN> MyCol.Count
        <SPAN style="color:darkblue">If</SPAN> MyCol(i)(0) < MyCol(j)(0) And _
        MyCol(i)(2) = MyCol(j)(2) <SPAN style="color:darkblue">Then</SPAN>
            Swap1 = MyCol(i)
            Swap2 = MyCol(j)
            MyCol.Add Swap1, before:=j
            MyCol.Add Swap2, before:=i
            MyCol.Remove i + 1
            MyCol.Remove j + 1
        <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
    <SPAN style="color:darkblue">Next</SPAN> j
<SPAN style="color:darkblue">Next</SPAN> i


Application.ScreenUpdating = <SPAN style="color:darkblue">False</SPAN>

<SPAN style="color:darkblue">Set</SPAN> ws = Sheets(2)
ws.[e:i].ClearContents
<SPAN style="color:darkblue">With</SPAN> ws.[e1:i1]
    .Value = [{"Group","Score","","Name","% Above Last"}] <SPAN style="color:green">'Set Your Headers</SPAN>
    .HorizontalAlignment = xlCenter
    .Font.Bold = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> MyCol.Count
    <SPAN style="color:darkblue">Set</SPAN> cl = ws.[f65536].End(3)(2)
    <SPAN style="color:darkblue">If</SPAN> i = 1 <SPAN style="color:darkblue">Then</SPAN> cl(, 0) = MyCol(i)(2)  <SPAN style="color:green">'Pabel group on first</SPAN>
    <SPAN style="color:darkblue">On</SPAN> <SPAN style="color:darkblue">Error</SPAN> <SPAN style="color:darkblue">GoTo</SPAN> 1
    <SPAN style="color:darkblue">If</SPAN> MyCol(i)(2) <> MyCol(i - 1)(2) <SPAN style="color:darkblue">Then</SPAN>
        cl(, 0) = MyCol(i)(2)
        Cnt.Add cl.Row
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
1:  <SPAN style="color:darkblue">On</SPAN> <SPAN style="color:darkblue">Error</SPAN> <SPAN style="color:darkblue">GoTo</SPAN> 0
    cl = MyCol(i)(0): cl(, 3) = MyCol(i)(1) <SPAN style="color:green">'Plant Score & Name</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">Set</SPAN> MyCol = <SPAN style="color:darkblue">Nothing</SPAN>

<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> Cnt.Count
    <SPAN style="color:darkblue">With</SPAN> ws.Range(ws.[i65536].End(3)(2), ws.Cells(Cnt(i) - 1, 9))
        .Formula = "=RC[-3]/R" & Cnt(i) - 1 & "C6-1"
        .Value = .Value
    <SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">Next</SPAN>

<SPAN style="color:darkblue">With</SPAN> ws.Range(ws.[i65536].End(3)(2), ws.[h65536].End(3).Item(, 2))
    .Formula = "=RC[-3]/R" & ws.[h65536].End(3).Row & "C6-1"
    .Value = .Value
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
<SPAN style="color:darkblue">Set</SPAN> Cnt = <SPAN style="color:darkblue">Nothing</SPAN>

ws.Range([i2], cl(, 4)).NumberFormat = "0.00%"
<SPAN style="color:darkblue">Set</SPAN> cl = <SPAN style="color:darkblue">Nothing</SPAN>
ws.[g:g].ColumnWidth = 3
ws.[e:f,h:i].EntireColumn.AutoFit
<SPAN style="color:darkblue">Set</SPAN> ws = <SPAN style="color:darkblue">Nothing</SPAN>
Application.ScreenUpdating = <SPAN style="color:darkblue">True</SPAN>

<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>

But not in process time, much slower than the last posted proc. Think the 3-d items/sorting on this collection is bogging it down a touch.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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