VBA Factorial Help Please :)

Joined
Sep 6, 2011
Messages
5
Reaction score
0
Hello All,

I need help with a homework that I've been working on, which is writing a code to find the factorial of a value where the constant include:

Const COL_N = 1 ' column for the n values
Const COL_NFACT = 2 ' column for the factorial values
Const ROW_START = 2 ' ignore header row

calculate factorials (n! = 1 * 2 * 3 * ... * (n–1) * n) using VBA and display them on a spreadsheet .


I have to create a subprogram that contains a loop that generates factorials in order, starting with 0! = 1, 1! = 1*0! = 1, 2! = 2*1! = 2, 3! = 3*2! = 6 and so on.

Notice that each step uses the next value of n and the previous factorial value to produce the next.



Given variables holding the row and column numbers, I have to assign a cell using one of these statements:


ActiveSheet.Cells(row, col).Value = myData

ActiveSheet.Cells(row, col) = myData

Some way of stopping the generation process. For this version there is a cell on the sheet named MaxFact. Pick up this value using the ActiveSheet.Range(name) notation, where name is a string constant or variable holding the name or address of the required cell. Stop the iteration when the factorial exceeds this value, but before displaying it (the algorithm structure should allow this).

Also if you are able to use the While structure to express this condition.

Thanks in Advance!
 
Back
Top