Excel: Creating a Factorial() Function

Last reviewed: November 2, 1994
Article ID: Q26395

SUMMARY

To compute the factorial of a number in versions 1.50, 2.20, or 3.00 of Microsoft Excel, the FACT function can be used.

To create a function that will compute factorials in versions 1.06 and earlier of Excel, do the following:

  1. Enter the following commands into a macro sheet:

          +---+-------------------------------------------------------+
    
          |   |                           A                           |
          +---+-------------------------------------------------------+
          | 1 | Factorial                                             |
          +---+-------------------------------------------------------+
          | 2 | =RESULT(1)                                            |
          +---+-------------------------------------------------------+
          | 3 | =ARGUMENT("number",1)                                 |
          +---+-------------------------------------------------------+
          | 4 | =SET.NAME("factorial.result",1)                       |
          +---+-------------------------------------------------------+
          | 5 | =IF(NOT(number>1),RETURN(factorial.result))           |
          +---+-------------------------------------------------------+
          | 6 | =SET.NAME("factorial.result",factorial.result*number) |
          +---+-------------------------------------------------------+
          | 7 | =SET.NAME("number",number-1)                          |
          +---+-------------------------------------------------------+
          | 8 | =GOTO(A5)                                             |
          +---+-------------------------------------------------------+
    
    

  2. Select cell A1.

  3. From the Formula menu, choose Define Name.

  4. Under Macro, select Function.

  5. Click OK.

To use the function macro in a worksheet, do the following:

  1. Make sure the macro sheet is open.

  2. Select the cell to contain the function.

  3. From the Formula menu, choose Paste Function.

  4. Scroll to the bottom of the list of functions.

  5. Select the desired function [which will be of the form MacroSheetName!Factorial()] and click OK.

  6. Enter the number to be factored between the parentheses and press RETURN.


KBCategory: kbother
KBSubcategory:

Additional reference words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00


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: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.