Product in vba/excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SANDRADEPAR
    New Member
    • Mar 2010
    • 14

    Product in vba/excel

    Can someone give some hints???
    Id like to know if someone have a code for visual basic/ excel to calculate the the product of a sequence of numbers in VBA, i'm using windowns 7/vista.The definition of the product of n numbers is https://es.wikipedia.or g/wiki/Productorio

    What i already tried:
    Function mo( j, n)


    Dim x As Double, j As Double

    x = 10 -1/n

    For j = 1 To n
    s = Application.Wor ksheetFunction. Product(x)

    Next
    mo = t
    End Function

    I used Application.Wor ksheetFunction. Product(x) from excel and nothing happened. It didn't work.

    x = 10 -1/n is the number generating function for j from 0 to n
    i want the Product of all the numbers that are generated from that equation.
    for example, from 1 to 10 the resulting numbers would be:9
    9,5 9,666666667 9,75 9,8 9,833333333 9,857142857 9,875 9,888888889 9,9
    P= 9,5* 9,666666667* 9,75* 9,8 * 9,833333333 *9,857142857 9,875* 9,888888889* 9,9 = 7400228969

    In general, i want Product function in VBA of all the numbers that are generated from that equation (x = 10 -1/n) in order to put in a simpler way inside another more large complicated (mind-blowing) equation .


    Code:
    Function mo( j,  n)
    
    
    Dim  x As Double, j As Double
    
    x = 10 -1/n
    
    For j = 1 To n
     s = Application.WorksheetFunction.Product(x)
    
    Next
    mo = t
    End Function
    I'm looking forward to receiving good news.

    Thanks in advance
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    I'm afraid I have little knowledge of Excel, but I suspect you want something more like

    Code:
     Function mo(J, n) As Double
    
        Dim i As Integer
        Dim x As Double
    
        mo = J
        For i = 1 To n
            x = J - (1 / i)
            mo = mo * x
        Next i
    
        mo = mo / J
    
    End Function
    If I Type Debug.Print (mo(10,10) I get 7400228969.4145 3

    I suspect it may need rounding off

    Phil

    Comment

    • SANDRADEPAR
      New Member
      • Mar 2010
      • 14

      #3
      OK. THANK YOU SO MUCK. MO WORKS NOW.
      But i need insert MO in other vba formula by using the same previous generating function for MO (x = 10 -1/n):
      Function summot(j, n) As Double
      For j = 1 To n
      sum = sum +Application.Co mbin(n,j)*Appli cation.Workshee tFunction.mo(n, j)
      Next
      summot= sum
      End Function

      For example, i'd like to calculate for j=9 n=9
      Can u tell me please how to calculate the sum above that?
      many thks in advance

      Code:
      Function summot(j, n) As Double
      For j = 1 To n
      sum = sum +Application.Combin(n,j)*Application.WorksheetFunction.mo(n,j)
      Next
      summot= sum
      End Function

      Comment

      • PhilOfWalton
        Recognized Expert Top Contributor
        • Mar 2016
        • 1430

        #4
        Sorry, I can't help further. As I said, Excel is not my forte.

        Phil

        Comment

        • SANDRADEPAR
          New Member
          • Mar 2010
          • 14

          #5
          ok many thks bro.

          Can Someone , please, provide further help? many thks in advance

          Comment

          Working...