在函数vba中使用已创建的函数



制作一个VBA函数,使用梯形规则计算积分但是我怎么能应用我在VBA中创建的函数在另一个函数中使用…这是我的代码(工作表)。函数不工作)

Option Explicit
Function funcion(x As Double) As Double
    funcion = 3 * (x ^ 3) + 5 * (x ^ 2) - 10 * x + 20
End Function
Function Sumatoria(a As Double, n As Double, h As Double) As Double
    Dim i As Integer
    Dim sum As Double
    i = 0
    sum = 0
    Do While (i <= n - 1)
        sum = sum + WorksheetFunction.funcion(a + i * h)
         i = i + 1
    Loop
    Sumatoria = sum
 End Function

这行得通:

Function Sumatoria(a As Double, n As Double, h As Double) As Double
    Dim i As Integer
    Dim sum As Double
    Dim temp As Double
    i = 0
    sum = 0
    Do While (i <= n - 1)
        temp = a + i * h
        sum = sum + funcion(temp)
         i = i + 1
    Loop
    Sumatoria = sum
 End Function

相关内容

  • 没有找到相关文章

最新更新