• +351 91 33 888 29
    • clico@clico.pt

    Excel VBA – Calculate Factorial

    factorials

    Excel VBA – Calculate Factorial

    Excel VBA Code - Calculate Factorial

    Well-structured VBA code for calculating the factorial of a number.

    Open Microsoft Excel, create a new blank book, after go to TAB Programmer or click Alt+F11 and access to VBA Project.

    Copy/paste code and try…

    Sub CalculateFactorial()
    Dim num As Integer
    Dim result As Double

    ‘ Input
    num = InputBox(“Enter a number:”)

    ‘ Calculate factorial
    result = Factorial(num)

    ‘ Output
    MsgBox “The factorial of ” & num & ” is ” & result
    End Sub

    Function Factorial(n As Integer) As Double
    If n = 0 Then
    Factorial = 1
    Else
    Factorial = n * Factorial(n – 1)
    End If
    End Function

    VBA_Factorial_1-1024x498 Excel VBA - Calculate Factorial
    VBA_Factorial_2 Excel VBA - Calculate Factorial
    VBA_Factorial_3-1024x391 Excel VBA - Calculate Factorial
    VBA_Factorial_4 Excel VBA - Calculate Factorial
    clicopt

    Deixe a sua mensagem

    Show Buttons
    Hide Buttons