# How to Use the Excel VBA Tan Function (2 Examples)

This article discusses the **VBA **Tan function. We will find the tangent values for the radian unit as well as for the degree unit.

## Purpose of the VBA Tan Function

To calculate the tangent values for angles in radians.

## Syntax of the VBA Tan Function

`Tan(Number As Double) `

## Arguments of the VBA Tan Function

Arguments | Explanation |
---|---|

Number As Double | The numerical value of the radian angle for which the tangent value will be calculated |

**Example #1: Get Value for Tan Angle with Radian**

Consider the following sample data. The angles are in radians. We will apply the VBA Tan function to get the tangent values.

- Copy the codes below and see the results in column C.

```
Sub Tan_Radian()
Dim xCell As Range
'Apply For Loop in a Range with Tan Function
For Each xCell In Range("B4:B9")
xCell.Offset(0, 1) = Tan(xCell.Value)
Next xCell
End Sub
```

**Example #2: Get Value for Tan Angle with Degree**

Now, we will want to get the tangent values for degree angles. But the fact is that the VBA Tan function takes the argument as radians by default. So, we need to convert the degree values into radians and calculate the tangent values. We will do this by applying the VBA codes below.

- Copy the codes below and see the results in column C.

```
Sub Tan_Degree()
Dim xDegree As Range
Dim rad_to_deg As Range
Dim xCell As Range
Set xDegree = Range("B4:B9")
'Apply For Loop in a Range to convert degrees into radian
For Each xDegree In Range("B4:B9")
xDegree.Offset(0, 0) = (xDegree * 3.14159265358979) / 180
Next xDegree
'Apply For Loop in a Range with Tan Function
For Each xCell In Range("B4:B9")
xCell.Offset(0, 1) = Tan(xCell.Value)
Next xCell
Set rad_to_deg = Range("B4:B9")
'Apply For Loop in a Range to convert degrees into radian
For Each rad_to_deg In Range("B4:B9")
rad_to_deg.Offset(0, 0) = (rad_to_deg * 180) / 3.14159265358979
Next rad_to_deg
End Sub
```

- See the results in column C with tangent values for the degree angles.

**Things to Keep in Mind**

- The Tan function accepts a single argument, which can either be a variable or a literal value. The argument must be a numeric expression.
- The Tan function returns an overflow error if the argument is outside the range of -1.79769313486231E308 to 1.79769313486231E308.

**Frequently Asked Questions**

**Q: What is the Tan function’s range of application?**

A: All real numbers, with the exception of odd multiples of pi/2, have the Tan function defined.

**Q: How do I convert degrees to radians in VBA?**

A: To convert degrees to radians in VBA, you can multiply the degree value by **Application.Pi / 180**. For example, to convert 45 degrees to radians, you can use the expression **45 * Application.Pi / 180**.

**Q: How do the Tan function and the Atan function differ from one another?**

A: The **Tan **function determines an angle’s tangent, whereas the **Atn **function determines the angle whose inverse tangent is an integer. To put it another way, the **Atn **function takes a tangent as input and returns the corresponding angle, whereas the **Tan **function takes an angle as input and returns the tangent.

**Conclusion**

From this article, you have learned how to use the VBA Tan function to determine the tangent values for two different units (radian and degree). 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!