As others have indicated, you can use Excel's built in FACT worksheet
function. However, you can roll your own with a recursive function in
VBA. Recursive functions are those function that call themselves. In
the code below, the Fact function calls itself decrementing the input
value until it is 1.
See
http://www.cpearson.com/Excel/RecursiveProgramming.aspx for an
introduction to recursion.
Function Fact(N As Long) As Long
If N = 1 Then
Fact = 1
Else
Fact = N * Fact(N - 1)
End If
End Function
Usage:
Sub AA()
Dim L As Long
L = Fact(6)
Debug.Print CStr(L) ' displays 120
End Sub
Then your original code will work with no modification.
Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
I have the following equation in my code:
TotalCalc = Fact(n + 4) / (Fact(4) * Fact(n))
When I compile, it highlights the first Fact and tells me "Sub or Function
not defined".
TIA