I am trying to write a sub to get the factorial of a number. From the code below, can someone tell me why I need to have the fac = 1 line before the For Next loop?
Sub factorial() Dim fac As Integer, i As Integer, Num As Integer Num = Range("a1").Value fac = 1 For i = 1 To Num fac = i * fac Next i Range("a2").Value = fac End Sub