PDA

View Full Version : Factorial help



DealErSing
03-12-2008, 11:40 PM
i need to write a code that

when the user click a command button, VBA will take the number from a textbox and calculate the factorial,

the only problem is that i can't use the factorial function, i must use a "do..loop" i searched everywhere and everyone uses the factorial function

Bob Phillips
03-13-2008, 01:44 AM
Function MyFact(val As Variant) As Long
Dim i As Long

val = Int(val)
MyFact = val
For i = val - 1 To 2 Step -1

MyFact = MyFact * i
Next i
End Function