Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

How do I correctly call a function/return a value in VBA?

$
0
0

Trying to code a method, and for every step I have to call another method (which I coded as a separate Sub) but it is not working.

Sub implicit()


'Setting limits and stepsize

x0 = 0
xfinal = 100
h = 5
Dim y2 As Double
Dim y As Double

'Calculating number of intervals
n = (xfinal - x0) / h

'Setting initial value
y = 100000

'Loop for implicit method
For i = 1 To n
    Call methodN(y)
    y2 = y + h * (0.1 * y2 - 0.0000008 * y2 ^ 2)
    Cells(2 + i, 3) = y2
    y = y2
Next i

End Sub

'N method

Sub methodN(y)

y2 = y - (y * (1 - 0.1 * h + 0.0000008 * h * y) - y) / (1 - 0.1 * h + 0.0000016 * h * y)


End Sub

When I put Return y2 in the second sub as the last line I get a compiler error. I know I'm not calling the Sub properly and I'm not returning the y2 value, can someone help?


Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>