|Article Time Stamp: 06 July 2008, 23:11:18 GMT+7|
Random Sort in Microsoft Excel
You can use Excel to pick three winners-1st, 2nd, and 3rd-chosen at random from a list in your spreadsheet. The easiest and fairest way to do this is to use Excel's RAND function in combination with its sorting capabilities.
Assume you have a three-column table in your spreadsheet, starting from column B and containing Name, Age, and ID No., in that order. You can place the RAND function in cell A2 and copy this down as many rows as needed, all the way to the end of your table. As soon as you do this, each cell in column A containing the RAND function will automatically return a random number by which you can sort the table. In other words, you can sort columns A, B, C, and D by column A in either ascending or descending order, and the three winners can be the top three names.
The RAND function is a volatile function that will recalculate automatically whenever an action takes place in Excel-e.g., entering data somewhere else, or forcing a recalculation of the worksheet by pressing F9. You'd better write down your winners quickly.
However, you can use this volatility to your benefit and record a macro that sorts data immediately after you recalculate and force the RAND function to return another set of random numbers. You then can attach this macro to a button so that each time you want to draw three winners, all you need to do is click the button and use the top three names.
For example, assume you have your data in columns B, C, and D and that row 1 is used for headings. First, place the heading RAND in cell A1. Enter =RAND( ) in cell A2 and copy down as far as needed. Then select any single cell and select Tools - Macro - Record New Macro....
Select columns A, B, C, and D and press F9 (to force a recalculation). Select Data - Sort and sort the data by column A. Stop recording the macro.
Next, select View - Toolbars - Forms. Select a button from the Forms toolbar and place it anywhere on the worksheet. Assign the macro you just recorded to this button and click OK. (Change the text for the button from Button 1 to something more meaningful, if you want.) (You can select column A and hide it completely, as there is no need for a user to see the random numbers generated.) Each time you click the button, your data will be sorted randomly, and you can just read off the top three names to be the winners.