Invalid procedure call or argument in Function

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
This error message in line vpp:

Invalid procedure call or argument

Code:
Function fn1(ByVal a, ByVal i, ByVal e, ByVal N, ByVal w, ByVal ta)
    Pi = Application.WorksheetFunction.Pi
    mhu = 398600    
    vpp = (mhu / Math.Sqr(mhu * a * (1 - e ^ 2))) * (-Math.Sin(ta * Pi / 180))
    fn1 = 2 * vpp
End Function
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I get that error if the Sqr function recieves a negative number.

so if this part evaluates to a negative number, you will get that error
mhu * a * (1 - e ^ 2)
 
Upvote 0
Function KeplerianToRandV(ByVal a, ByVal i, ByVal e1, ByVal N, ByVal w, ByVal ta)
Pi = Application.WorksheetFunction.Pi
mhu = 398600
If e1 <> 1 And e1 * Math.Cos(ta * Pi / 180) <> -1 Then
vpp = (mhu / Math.Sqr(mhu * a * (1 - e1 ^ 2))) * (-Math.Sin(ta * Pi / 180))
Else
MsgBox("Divides by Zero")
End If
End Function

Still getting a Procedural error.
 
Upvote 0
Can you post your call to the function, what values are being provided for each variable (a i e1 N w ta)
 
Upvote 0
Maybe ...

Code:
Function fn1(a As Double, e As Double, ta As Double) As Variant
    Const pi        As Double = 3.14159265358979
    Const D2R       As Double = pi / 180#
    Const mhu       As Double = 398600#
    If e <= 1 Then
        fn1 = -2 * mhu / Sqr(mhu * a * (1 - e ^ 2)) * Sin(ta * D2R)
    Else
        fn1 = CVErr(xlErrDiv0)
    End If
End Function

You're passing several arguments that aren't used.
 
Last edited:
Upvote 0
That's fine, but the function doesn't use them.
 
Upvote 0
e1=
0.00149

<tbody>
</tbody>

ta=
132.5478

a=
6794

<tbody>
</tbody>


<tbody>
</tbody>
rv0 = fn1(a, e1, ta)
 
Last edited:
Upvote 0
I can see that they appear in the function's signature; my point is, they are not used by the function:

Code:
vpp = (mhu / Math.Sqr(mhu * a * (1 - e1 ^ 2))) * (-Math.Sin(ta * Pi / 180))
Where do N, i, and w appear in that expression?
 
Upvote 0
You seem to have e and i reversed...

In the function you posted, it's declared as
Function fn1(ByVal a, ByVal i, ByVal e, ByVal N, ByVal w, ByVal ta)
i comes before e

But in the call to the function, you put
rv0 = fn1(a, e, i, N, w, 180)
e comes before i



If this isn't it..
Please....
Post the values (values, not cell refernces) of ALL the variables
And the actual code that is trying to USE the function.
 
Upvote 0

Forum statistics

Threads
1,216,416
Messages
6,130,486
Members
449,584
Latest member
LeChuck

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top