Here's the Atan2 function. Simply copy/paste this into a new module
Best Regards
Maurice St-Cyr
Micro Systems Consultants, Inc.
Function ATan2(x As Double, Y As Double) As Double
'
' Returns the ArcTangent based on X and Y coordinates
' If both X and Y are zero an error will occur.
'
' The positive X axis is assumed to be 0, going poistive in the
' counterclockwise direction, and negative in the clockwise direction.
'
If x = 0 Then
If Y = 0 Then
ATan2 = 1 / 0
ElseIf Y > 0 Then
ATan2 = PI() / 2
Else
ATan2 = -PI() / 2
End If
ElseIf x > 0 Then
If Y = 0 Then
ATan2 = 0
Else
ATan2 = Atn(Y / x)
End If
Else
If Y = 0 Then
ATan2 = PI()
Else
ATan2 = (PI() - Atn(Abs(Y) / Abs(x))) * Sgn(Y)
End If
End If
End Function
I haven't seen the PI() function in VBA / Access VBA.
Is it an inbuilt function or a UDF?
If you are using the Excel PI() function, then you need to automate Excel
and in this case, it is perhaps more convenient to simply use the Atan2()
function in Excel.
I haven't seen the PI() function in VBA / Access VBA.
Is it an inbuilt function or a UDF?
If you are using the Excel PI() function, then you need to automate Excel
and in this case, it is perhaps more convenient to simply use the Atan2()
function in Excel.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.