Excel VBA Sin Function

VBA Sin Function: The Sin function in VBA returns the sine value for a supplied angle.

Syntax

Sin (Number)

Parameter

Number (required) –This parameter represents the angle (in radians) to calculate the sine value.

Return

This function returns the sine value for a supplied angle.

Example 1

Sub SinFunction_Example1()
 ' Calculating the sine for the specified number.
 Dim sin_val1 As Double
 Dim sin_val2 As Double
 Dim sin_val3 As Double
 sin_val1 = Sin(90)
 ' The variable sin_val1 will return value 0.893996663600558. 
 Cells(1, 1).Value = sin_val1
 sin_val2 = Sin(0)
 ' The variable sin_val2 will return value 0.
 Cells(2, 1).Value = sin_val2
 sin_val3 = Sin(3.14159265358979)
 ' The variable sin_val3 will return value 3.23108510433268E-15.
 Cells(3, 1).Value = sin_val3
 End Sub 

Output

0.893996664
0
3.23E-15
VBA Sin Function

Example 2

Sub SinFunction_Example2()
 ' Calculating the sine for the specified number.
 Dim sin_val As Double
 sin_val = Sin(0.785398163397448)
 ' The variable sin_val will return value 0.707106781186547.
 Cells(1, 1).Value = sin_val
 End Sub 

Output

0.707106781186547

VBA Sin Function

Example 3

Sub SinFunction_Example3()
 ' Calculating the sine for the specified number.
 Dim sin_val As Double
 Const pi = 3.14159265358979
 ' Converting 60 degrees to radians by multiplying by pi/180.
 sin_val = Sin(60 * pi / 180) 
 ' The variable sin_val will return radina 0.866025403784438.
 Cells(1, 1).Value = sin_val
 End Sub 

Output

0.866025403784438

VBA Sin Function