Microsoft KB Archive/169169

From BetaArchive Wiki

Microsoft Knowledge Base

How to Automatically Return a Random Value from a List

Last reviewed: May 29, 1997
Article ID: Q169169

The information in this article applies to:

  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel 97 for Windows

SUMMARY

By using a combination of the INDEX, INT, ROWS, and RAND functions in a worksheet formula in Microsoft Excel, you can automatically return a random value from a list on a worksheet.

MORE INFORMATION

The following example formula automatically returns a random value from a list on a worksheet

   =INDEX(<Range>,INT(ROWS(Range)*RAND())-1,1)

where <Range> is the address of the cells that contain the data.

To use the formula, do the following:

  1. Type the following information into a worksheet:

          A1:  A
          A2:  B
          A3:  C
          A4:  D
          A5:  E
          A6:  F
          A7:  G
          A8:  H
          A9:  I
          A10: J
  2. In cell C1, type the following formula:

          =INDEX(A1:A10,INT(ROWS(A1:A10)*RAND())-1,1)
  3. To generate a new value in cell C1, press F9 to recalculate the formula.

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q44738
   TITLE     : Generating a Random Number without RAND() in Excel

   ARTICLE-ID: Q96746
   TITLE     : XL: Using RAND() to Generate Randomly Distributed Integers
 


Keywords : kbusage xlformula

Version : 5.0 5.0a 5.0c 7.0 97
Platform : MACINTOSH WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 29, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.