Monday, April 25, 2011

Reorder/shuffle values in a row/column in Excel.

Is it possible to shuffle randomly, values in rows or columns in a excel sheet. Is there any function/macro for that? How do i do this?

-ad.

From stackoverflow
  • Hm... just as simple solution without programming. For example, you have a column of data (A):

    23
    78
    12
    78
    

    Just add another one column - B. Each cell of column B must be a function RAND():

    A     B
    --    --
    23    =RAND()
    78    =RAND()
    12    =RAND()
    78    =RAND()
    

    Now you can sort rows by column B and get desired solution.

  • Let's assume your values are in cells A1:A8

    1. Enter the formula =RANDBETWEEN(1,100000)+ROW()/100000 in cells B1:B8
    2. Enter the formula =RANK(B1,$B$1:$B$8) in cells C1:C8
    3. Enter the formula =INDEX($A$1:$A$8,C1) in cells D1:D8

    Every time you calculate (hit F9), a newly shuffled list will appear in cells D1:D8

    goldenmean : @Ejames: I did not see a function RANDBETWEEN in my excel version(Office 2003). How do i get that function or am i missing anything?
    e.James : @goldenmean: It is part of the "Analysis ToolPak" add-in, which comes with Excel, but isn't always enabled. If you do a search for RANDBETWEEN in Excel help, it provides some information on how to install it.

0 comments:

Post a Comment