The VBA Atn Function

Related Function:
VBA Tan

Description

The VBA Atn function returns the arctangent (between -π/2 and +π/2)of a supplied number, in radians.

The syntax of the function is:

Atn( Number )

Where the supplied Number is the number that you want to calculate the arctangent of.


VBA Atn Function Examples

Example 1

' Calculate the arctangent of three different numbers.
Dim rad1 As Double
Dim rad2 As Double
Dim rad3 As Double
rad1 = Atn( -1 )
' The variable rad1 is now equal to -1.785398163397448.
rad2 = Atn( 0 )
' The variable rad2 is now equal to 0.
rad3 = Atn( 0.577350269189626 )
' The variable rad3 is now equal to 0.523598775598299.

In the above VBA code:


Example 2 - Convert the Result of the Atn Function Into Degrees

If you want the result of the Atn function to be expressed in degrees, instead of radians, you can covert the returned value into degrees by multiplying it by 180 / π. An example of this is provided below:

' Calculate the arctangent of 0.577350269189625.
' First calculate the arctangent in radians.
Dim rad1 As Double
rad1 = Atn( 0.577350269189625 )
' The variable rad1 is now equal to 0.523598775598298 (radians).
' Convert the radians into degrees by multiplying by 180/pi.
Const pi = 3.14159265358979
Dim deg1 As Double
deg1 = rad1 * 180 / pi
' The variable deg1 is now equal to 30 (degrees).

In the above VBA code:

Note that, in order to make the code more readable, the value 3.14159265358979 (π) has been assigned to the constant, pi, which is used in the conversion from radians to degrees.


VBA Atn Function Error

If the Atn function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box