Back

About MrExcel
Consulting Services
Learn Excel Resources
Challenge of the Month
MrExcel Seminars

Message Board

MrExcel Store
Podcast
Search
Contact
Home

 

 

Past Tip of the Day

 

Someone (why the rash of people not giving their name?) wrote: I have a column of 50 numbers and want to randomly select 5 of them. Can this be done?

There are several approaches to this. Here is one way to accomplish this. Let's say that your 50 numbers are in cells A2:A51.


  • Highlight cells B2:B51
  • Enter the formula =RAND() and hit Ctrl+Enter. This will enter the formula in all 50 cells at once
  • Copy B2:B51 with Ctrl+c
  • PasteSpecial the formulas into values by using Edit - PasteSpecial - Values - OK

You have now assigned a random number to each row. You could sort by column B and take the top 5, the bottom 5, whichever you prefer. If for some reason you can not sort the data, you could use column C and enter a Rank function.

  • In cell C2, enter this formula: =RANK(B2,$B$2:$B$51)<6
  • Copy the formula from C2 to C2:C51

Anything with a value of TRUE is one of the 5 randomly selected numbers

By Bill Jelen on 12-Nov-2001

MrExcel.com Consulting can be hired to implement this concept, or many other cool applications, with your data.

MrExcel.com provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures on this web site are provided "as is" and we do not guarantee that they can be used in all situations.

 

Excel is a registered trademark of the Microsoft® Corporation.

All contents Copyright 1998-2008 by MrExcel Consulting.