1

I am trying to run Rungenkutta differential problem in excel VBA program is as follows

Sub Rungenkutta()


Dim Noofitrations As Integer
Dim n As Integer
Dim ii As Integer
Noofitrations = Cells(2, 10)
n = Cells(3, 10)
h = Cells(3, 4)
col = 8
x0 = Cells(col, 9)
y0 = Cells(col, 10)

For i = 1 To Noofitrations

 Cells(7, 3) = x0
 Cells(7, 4) = y0
 xn = x0 + h
 yn = y0 + Cells(18, 3)

 ii i Mod n
 If ii = 0 Then
    col = col + 1
    Cells(col, 9) = xn
    Cells(col, 10) = yn
 End If
 x0 = xn
 y0 = yn

Next


End Sub

but while running I am getting "VBA excel compile error : Expected Sub,Function, or property"

I am not understanding what shall i do to run the program

2
  • Does it point to a line of your code when it fails? Commented Jul 22, 2013 at 1:34
  • ii i Mod n isn't legal VBA - should this be ii = i Mod n instead? Commented Jul 22, 2013 at 1:35

1 Answer 1

2

Your problem is with the Mod operator. VBA doesn't recognize the syntax you provided.

Here is some documentation for the Mod operator - http://msdn.microsoft.com/en-us/library/se0w9esz.aspx

Th Mod operator is a binary operator and requires one left and one right argument.

You need to change

ii i Mod n   

to

ii = i Mod n

Here is the revised example you provided.

Sub Rungenkutta()


Dim Noofitrations As Integer
Dim n As Integer
Dim ii As Integer
Noofitrations = Cells(2, 10)
n = Cells(3, 10)
h = Cells(3, 4)
col = 8
x0 = Cells(col, 9)
y0 = Cells(col, 10)

For i = 1 To Noofitrations

Cells(7, 3) = x0
Cells(7, 4) = y0
xn = x0 + h
yn = y0 + Cells(18, 3)

ii = i Mod n
If ii = 0 Then
   col = col + 1
   Cells(col, 9) = xn
   Cells(col, 10) = yn
End If
x0 = xn
y0 = yn

Next


End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.