Excel VBA Atn Function

VBA Atn Function: The Atn function in VBA returns the arctangent between quadrant -?/2 and +?/2 for the specified number, in radians.

Syntax

Atn (Number)

Parameter

Number (required) – This parameter represents the number that the user wants to calculate the arctangent of.

Return

This function returns the arctangent between quadrant -?/2 and +?/2 for the specified number, in radians.

Example 1

Sub AtnFunction_Example1()
 ' Calculating the arctangent for given numbers.
 Dim atn_val1 As Double
 Dim atn_val2 As Double
 atn_val1 = Atn(-2)
 ' The variable atn_val1 will return -1.10714871779409.
 Cells(1, 1).Value = atn_val1
 atn_val2 = Atn(0)
 ' The variable atn_val2 will return 0.
 Cells(2, 1).Value = atn_val2
 End Sub 

Output

-1.107148718
0
Excel VBA Atn Function

Example 2

Sub AtnFunction_Example2()
 ' Calculating the arctangent for given number.
 Dim atn_val1 As Double
 atn_val1 = Atn(0.977368999622)
 ' The variable atn_val1 will return 0.773953656919952.
 Cells(1, 1).Value = atn_val1
 End Sub 

Output

0.773953656919952

Excel VBA Atn Function

Example 3

Sub AtnFunction_Example3()
 ' Calculating the arctangent for given number.
 ' Convert the radians into degrees by multiplying by 180/pi _value.
 Dim atn_val As Double
 Const pi_val = 3.14159265358979
 atn_val = 0.523598775598298 * 180 / pi_val
 ' The variable atn_val will return 30 (degrees).
 Cells(1, 1).Value = atn_val
 End Sub 

Output

30

Excel VBA Atn Function

Example 4

Sub AtnFunction_Example4()
 ' Calculating the arctangent for given number.
 Dim atn_val1 As Double
 'for other formats apart from number
 atn_val1 = Atn("Hey")
 ' The variable atn_val1 will return mis match error.
 Cells(1, 1).Value = atn_val1
 End Sub 

Output

Excel VBA Atn Function