VBA - Trapez reglen - Runtime error 13
Hej Experter..Jeg får Runtime error 13 i nederstående kode. Er der nogen der kan fortælle mig hvad jeg gør galt?
(bruger office 2007 hvis har nogen betydning...)
Function numInt() As String
'Brug af trapezreglen
'*** Temp start ***
Dim express As String
Dim var As String
Dim p0 As Double
Dim p1 As Double
express = "2*x+1"
var = "x"
p0 = 0
p1 = 25.01
'*** TEMP slut ***
'*** Dim start ***
Dim opdel As Double
Dim ft1 As Double
Dim ft2 As Double
Dim t1 As Double
Dim t2 As Double
Dim A As Double
Dim Atmp As Double
Dim p_space As Double
Dim i As Integer
'*** Dim slut ***
'*** præcision
opdel = 1000
'*** beregn afstand mellem opdellinger (del integraler)
p_space = (p1 - p0) / opdel
For i = 0 To opdel - 1
'beregn t1 og t2
t1 = p0 + p_space * i
t2 = p0 + p_space * (i + 1)
ft1 = Evaluate(Replace(express, var, t1))
ft2 = Evaluate(Replace(express, var, t2))
' ^^ RUN TIME ERROR 13 ^^
'*** find del areal
Atmp = (t2 - t1) * (ft2 - ft1) / 2
'*** sum over delarealet
A = A + Atmp
Next i
MsgBox A
End Function