Change column order

Andy0311

Board Regular
Joined
Oct 16, 2019
Messages
55
Office Version
365, 2016
Platform
Windows
Hello,

Shown below is a simple table showing a list of students and their grades for tests they periodically take. I send the results to them so that they can see how everyone is performing without knowing each others scores. I would like to automatically anonymise the columns each time I send the results so that the students won't be in the same position as last time. I need some advice on how to approach this. Thank you.

Andy


Share the table with out the first row with the group initially
Actual NameAndyBrianJaneMikeSueTom
Identifier #123456
Test 18598100738895
Test 29091100848589
Test 390100100879287
Average88.396.3100.081.388.390.3
Share the table except for the first row with the group subsequently with column order changed
Actual NameBrianJaneAndySueMikeTom
Identifier #123456
Test 19810085887395
Test 29110090858489
Test 310010090928787
Average96.3100.088.388.381.390.3

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

Desired Result to be able to change the column order each time I send the report out
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
8,803
There are lots of ways to do this, formulas or VBA. Here's a formula option.

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th><th>H</th><th>I</th><th>J</th><th>K</th><th>L</th><th>M</th><th>N</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style="color: #333333;background-color: #FAFAFA;;">Actual Name</td><td style="color: #333333;background-color: #FAFAFA;;">Andy</td><td style="color: #333333;background-color: #FAFAFA;;">Brian</td><td style="color: #333333;background-color: #FAFAFA;;">Jane</td><td style="color: #333333;background-color: #FAFAFA;;">Mike</td><td style="color: #333333;background-color: #FAFAFA;;">Sue</td><td style="color: #333333;background-color: #FAFAFA;;">Tom</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">0.172551295</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">0.52781</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">0.2664</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">0.61943</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">0.11128</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style="color: #333333;background-color: #FAFAFA;;">Identifier #</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">1</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">2</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">4</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">5</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">6</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">4</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">2</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">1</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">5</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style="color: #333333;background-color: #FAFAFA;;">Test 1</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">85</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">98</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">73</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">95</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="color: #333333;background-color: #FAFAFA;;">Test 1</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">73</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">98</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">85</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="color: #333333;background-color: #FAFAFA;;">Test 2</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">90</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">91</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">84</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">85</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">89</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="color: #333333;background-color: #FAFAFA;;">Test 2</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">84</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">91</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">90</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">85</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style="color: #333333;background-color: #FAFAFA;;">Test 3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">90</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">87</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">92</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">87</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="color: #333333;background-color: #FAFAFA;;">Test 3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">87</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">90</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">92</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">6</td><td style="color: #333333;background-color: #FAFAFA;;">Average</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">96.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">81.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">90.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;"></td><td style="background-color: #FAFAFA;;">Average</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">81.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">96.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">100</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88.3</td><td style="text-align: right;color: #333333;background-color: #FAFAFA;;">88.3</td></tr></tbody></table><p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet4</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">J1</th><td style="text-align:left">=RAND(<font color="Blue"></font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">J2</th><td style="text-align:left">=RANK(<font color="Blue">J1,$J$1:$N$1</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">J3</th><td style="text-align:left">=INDEX(<font color="Blue">$B:$G,ROW(<font color="Red"></font>),J$2</font>)</td></tr></tbody></table></td></tr></table><br />

Put the J1 and J2 formulas in and copy them to the right as far as needed. Put the J3 formula in and copy right and down as needed. The columns will be randomized every time you make a change to the sheet. You can just press F9 to recalculate them too.
 

Andy0311

Board Regular
Joined
Oct 16, 2019
Messages
55
Office Version
365, 2016
Platform
Windows
There are lots of ways to do this, formulas or VBA. Here's a formula option.

ABCDEFGHIJKLMN
1Actual NameAndyBrianJaneMikeSueTom0.1725512950.527810.26640.619430.11128
2Identifier #12345642315
3Test 18598100738895Test 173981008588
4Test 29091100848589Test 284911009085
5Test 390100100879287Test 3871001009092
6Average88.396.310081.388.390.3Average81.396.310088.388.3

<tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
J1=RAND()
J2=RANK(J1,$J$1:$N$1)
J3=INDEX($B:$G,ROW(),J$2)

<tbody>
</tbody>

<tbody>
</tbody>



Put the J1 and J2 formulas in and copy them to the right as far as needed. Put the J3 formula in and copy right and down as needed. The columns will be randomized every time you make a change to the sheet. You can just press F9 to recalculate them too.
Thanks, Eric. Great help. I really appreciate it. Andy
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,426
Office Version
2010
Platform
Windows
Thanks, Eric. Great help. I really appreciate it. Andy
Question: Did you always want to keep the same Identifier # associated with their same scores the way Eric's solution does? I ask because your original post seemed to disassociate the Identifier # from the names and scores.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,426
Office Version
2010
Platform
Windows
Question: Did you always want to keep the same Identifier # associated with their same scores the way Eric's solution does? I ask because your original post seemed to disassociate the Identifier # from the names and scores.
Here is a VBA macro that will randomly mix your columns...
Code:
Sub RandomizeStudentColumns()
  Dim Cnt As Long, RndIndx As Long, Cols As Variant, Tmp As Variant
  Cols = [TRANSPOSE(ROW(2:7))]
  For Cnt = 6 To 1 Step -1
    RndIndx = [RANDBETWEEN(1,6)]
    Tmp = Cols(RndIndx)
    Cols(RndIndx) = Cols(Cnt)
    Cols(Cnt) = Tmp
  Next
  Range("B1", Cells(Rows.Count, "G").End(xlUp)) = Application.Index(Cells, [ROW(1:6)], Cols)
  [B][COLOR="#FF0000"]Range("B2:G2") = [{1,2,3,4,5,6}][/COLOR][/B]
End Sub
This code keeps the Identifier #'s in the order 1, 2, 3, 4, 5, 6 as your original post shows. If you want the Identifier # to move with the names the way Eric's formula solution does, then simply remove the line of code I show in red.
 

Andy0311

Board Regular
Joined
Oct 16, 2019
Messages
55
Office Version
365, 2016
Platform
Windows
Question: Did you always want to keep the same Identifier # associated with their same scores the way Eric's solution does? I ask because your original post seemed to disassociate the Identifier # from the names and scores.
Yes, I did. Students will look at the group report and often times email me, and ask,"What student am I in the report?" That way a student whose identifier is #3 will always be #3 . His or her column position, however, may be different. Thanks for the feedback, Rick.

Andy
 

Andy0311

Board Regular
Joined
Oct 16, 2019
Messages
55
Office Version
365, 2016
Platform
Windows
Thank you so much, Rick. I will save and try this out. I appreciate your input.

Andy
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,426
Office Version
2010
Platform
Windows
Thank you so much, Rick. I will save and try this out. I appreciate your input.
It occurs to me that you may give more tests later on and, in the future, you may have more or less students, so here is my code fully generalized so that it will adapt automatically to the number of students and the number of test shown on the worksheet (that way you will be able to use this for any of your classes, either now or in the future)...
Code:
Sub RandomizeStudentColumns()
  Dim Cnt As Long, RndIndx As Long, NumberOfStudents As Long, LastRow As Long, Cols As Variant, Tmp As Variant
  NumberOfStudents = Cells(1, Columns.Count).End(xlToLeft).Column - 1
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Cols = Evaluate("TRANSPOSE(ROW(2:" & NumberOfStudents + 1 & "))")
  For Cnt = UBound(Cols) To 1 Step -1
    RndIndx = Evaluate("RANDBETWEEN(1," & UBound(Cols) & ")")
    Tmp = Cols(RndIndx)
    Cols(RndIndx) = Cols(Cnt)
    Cols(Cnt) = Tmp
  Next
  Range("B1:G" & LastRow) = Application.Index(Cells, Evaluate("ROW(1:" & LastRow & ")"), Cols)
End Sub
Just run the code whenever you want to randomly mix the student columns around. Easiest would be to put a Form's Button on the worksheet and assign my code as the macro for that button, then all you have to do is click the button to mix the columns (you may want to do this several times is the random number generator does not move all of the columns from their current location).
 
Last edited:

Andy0311

Board Regular
Joined
Oct 16, 2019
Messages
55
Office Version
365, 2016
Platform
Windows
Again, thank you, Rick. Great help!

Andy
 

Forum statistics

Threads
1,078,338
Messages
5,339,638
Members
399,317
Latest member
mLife

Some videos you may like

This Week's Hot Topics

Top