# How to Use VBA Atn Function in Excel (2 Examples)

The arctangent of a number, expressed in radians, is what the VBA’s Atn function computes. In a cartesian coordinate system, it is a trigonometric function that is used to determine the angle between a given point and the x-axis. In this article, we will show you 2 examples of how to use the VBA Atn function in Excel.

**Purpose** of the Atn Function

The primary objective of the VBA Atn function is to determine the arctangent of a specified number. The arctangent is the inverse of the tangent function, which is used to determine how much one side of a right triangle is greater than the other.

**Syntax** of the Atn Function

`Atn(Number As Double)`

VB**Arguments** of the Atn Function

Argument | Explanation |
---|---|

Number As Double | The number for which we need to calculate the angle for the tangent. |

**Example #1 Use the VBA Atn Function to Get Angle in Radians**

We will calculate the arc tan or the inverse tan in radian units for the following numerical values. In order to do this, we will use the VBA Atn function, which by default provides the angle value of the inverse tan in radians.

- Copy the following codes and press F5 to run into your Module.

```
Sub Atn_Radian()
Dim xCell As Range
'Apply For Loop with Atn Function
For Each xCell In Range("B4:B8")
xCell.Offset(0, 1) = Atn(xCell.Value)
Next xCell
End Sub
```

VB- In the image below, output values are displayed along with arc tan values in radian units.

**Example #2 Use the VBA Atn Function to Get Angle in Degrees**

The Atn function cannot calculate the angle values in degrees. To do that, we will apply the following VBA codes.

- Copy and run the codes below.

```
Sub Atn_Degree()
Dim Pi As Long
Dim xCell As Range
Dim xCellValue As Range
Dim Atn_Degree As Range
'Apply For Loop with Atn function
For Each xCell In Range("B4:B8")
xCell.Offset(0, 1) = Atn(xCell.Value)
Next xCell
Pi = 3.14159265358979
Set xCellValue = Range("C4:C8")
For Each xCellValue In Range("C4:C8")
'Offset function for (0, 1) value will place the result in the next column
xCellValue.Offset(0, 1) = (xCellValue * 180) / 3.14159265358979
Next xCellValue
End Sub
```

VB- So, you will get the arc tan values in radian units along with degree units in column C.

**Things to Keep in Mind**

- The Atn function cannot perform for a range of values. So, you have to apply the For loop to get the values for the Atn function in a range.
- The ATN function yields a result in the range of -/2 and /2 radians (-90 and 90 degrees). If you want the outcome to be between 0 and 2 radians (between 0 and 360 degrees), you must add or subtract the right number of times the reciprocal of.
- The input values in the Atn function must be numerical values. Otherwise, it will show a run-time error for other expressions.

**Frequently Asked Questions**

**Q: The ATN and ATAN functions in VBA differ from one another, but how?**

A: In VBA, there is no distinction between ATN and ATAN functions. They simply refer to the same mathematical function by different names.

**Conclusion**

From the above discussions, you have learned two ways to use the VBA Atn function in Excel. We have shown you the outcome of the Atn function with two different units. These, in our opinion, will improve your professional work life in some way. If you have any additional questions, kindly post them in the comment section below. You will answer by offering solutions from the Solved Excel research department. Stay safe and get connected with us!