This is a classic exercise in job selection processes.
Solved Exercise
Exercise Solution
-
First, we create a function and define the input data as Integer and the output data as Long (as the number may increase considerably)
Function FacTorial(N As Long) As Double
-
We declare the variables and assign the value 1 to the variable Result. Remember that zero factorial equals to one (0! = 1)
Dim i As Double
Dim Result As Double
Result = 1
-
We create a For Next loop, whose final value (N!) comes from the input of the function, in which each iteration advance a step in the multiplication (accumulating the result in the variable Result).
For i = 1 To N
Result = Result * i
Next i
FacTorial = Result
Consolidated Answer
Function FacTorial(N As Integer) As Double
Dim i As Integer
Dim Result As Double
Result = 1
For i = 1 To N
Result = Result * i
Next i
FacTorial = Result
End Function
SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.
Excel ® is a registered trademark of the Microsoft Corporation.
© 2025 SuperExcelVBA | ABOUT