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
clicopt
Search
Artigos Recentes
- Missão Backup
- Constroi o Computador
- Jardim dos Números
- EuroVault360 | Gestão Financeira Inteligente
- Aprender formas nunca foi tão divertido!
- Cansado de formulários em PDF? Crie uma app simples com Power Apps
- Comparar dois ficheiros HTML no Power Automate
- Como Criar E-mails Automáticos de Aniversário no Power Automate
- Guia Prático: Espelhar Todas as Listas do SharePoint com Power Automate
- Power BI vs Excel: Quando Usar Cada Ferramenta?