Excel VBA Tan Function
VBA Tan Function: The Tan function in VBA returns the tangent for the specified angle in radians.
Syntax
Tan (Number)
Parameter
Number (required) – This parameter represents the angle supplied in radiant that you want to calculate the tangent of.
Return
This function returns the tangent of a supplied angle in radians.
Example 1
Sub TanFunction_Example1() ' Calculating the tangent for the specified number. Dim tan_val1 As Double Dim tan_val2 As Double Dim tan_val3 As Double tan_val1 = Tan(90) ' The variable tan_val1 will return value -1.99520041220824. Cells(1, 1).Value = tan_val1 tan_val2 = Tan(0) ' The variable tan_val2 will return value 0. Cells(2, 1).Value = tan_val2 tan_val3 = Tan(3.14159265358979) ' The variable tan_val3 will return value -3.23108510433268E-15. Cells(3, 1).Value = tan_val3 End Sub
Output
-1.995200412 |
0 |
-3.23109E-15 |
Example 2
Sub TanFunction_Example2() ' Calculating the tangent for the specified number. Dim tan_val As Double tan_val = Tan(0.785398163397448) ' The variable tan_val will return value 1.61977519054386. Cells(1, 1).Value = tan_val End Sub
Output
1.61977519054386
Example 3
Sub TanFunction_Example3() ' Calculating the tangent for the specified number. Dim tan_val As Double Const pi = 3.14159265358979 ' Converting 60 degrees to radians by multiplying by pi/180. tan_val = Tan(60 * pi / 180) ' The variable tan_val will return radian 1.73205080756887. Cells(1, 1).Value = tan_val End Sub
Output
1.73205080756887