n!=n×(n−1)×(n−2)×⋅⋅⋅

Wazyo

New Member
Joined
Sep 6, 2018
Messages
1
I need to do this in excel with vba for school.
Create a subroutine Factorial(n) that creates an array of size n. The first element ofthe array is 1. The next element is 1*2. Next is 1*2*3, etc. Formula: for n>1, ifelement ‘n’ is x then Xn = Xn-1 * n.
For example, Factorial(6) creates this array:

1 2 6 24 120 720
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
And what have you tried so far?
 
Upvote 0
Is this a homework assignment? If so, we don't do homework for you. After all, what do you learn if we do the work? If you start to do the coding and get stuck on a concept, we will try to talk you past it, but you should not expect us to to the work that your teacher expects you to do. With that said, here is VB function (for information purposes only) that will calculate exact factorials up to a value of N equal to 31 which is a 34 digit number (it will report an approximate value in scientific notation for larger values of N). LET ME CAUTION YOU though, if you try to turn this code into your teacher as if it were your own work, I can GUARANTEE you that your teacher will know that you did not write the code as it uses techniques beginner (and even some intermediate) programmers would not know how to use.
Code:
Function BigFactorial(N As Long) As Variant
  Dim X As Long
  If N < 28 Then
    BigFactorial = CDec(1)
    For X = 1 To N
      BigFactorial = X * BigFactorial
    Next
  ElseIf N > 31 Then
    BigFactorial = CDbl(1)
    For X = 1 To N
      BigFactorial = X * BigFactorial
    Next
  Else
    BigFactorial = CDec("10888869450418352160768")
    For X = 28 To N
      BigFactorial = X * BigFactorial
    Next
    BigFactorial = BigFactorial & "000000"
  End If
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top