Astra

How to Use the Excel VBA Sin Function (2 Examples)

Estimated reading: 4 minutes

Similar to the general Excel SIN function, Excel VBA also has a dedicated function to get the Sine values for radian angles. So, you can directly apply the Sin function while writing a program with VBA. This article demonstrates how to get sine values for radians and degree angles with the Excel VBA Sin function.

Excel VBA Sin Function to Find Sine Values
Excel VBA Sin Function to Find Sine Values

Purpose of the VBA Sin Function

When given an angle, the Sin function calculates the ratio of the height divided by its hypotenuse for a right-angled triangle. The value range for the Sin function is -1 to 1.

Trigonometrical Expression of Sine Angle
Trigonometrical Expression of Sine Angle

Syntax of the VBA Sin Function

Sin(Number As Double)

Syntax of the Excel VBA Sin Function
Syntax of the Excel VBA Sin Function

Arguments of the VBA Sin Function

ArgumentExplanation
Number As DoubleThe radian angle value for which the Sine value is calculated

Example #1: Get Value for Sin Angle with Radian

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

Sample Data Table
Sample Data Table 1
  • 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 Sin Function
For Each xCell In Range("B4:B9")
xCell.Offset(0, 1) = Sin(xCell.Value)
Next xCell

End Sub
Excel VBA Sin Function for a Range of Value
Excel VBA Sin Function for a Range of Value

Example #2: Get Value for Sin Angle with Degree

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

Sample Data Table 2
Sample Data Table 2
  • 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 * Application.Pi) / 180
Next xDegree

'Apply For Loop in a Range with Sin Function
For Each xCell In Range("B4:B9")
xCell.Offset(0, 1) = Sin(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) / Application.Pi
Next rad_to_deg

End Sub
Excel VBA Code to Find the Sine Values for Degree Angles
Excel VBA Code to Find the Sine Values for Degree Angles
  • See the results in column C with tangent values for the degree angles.
Return Values for Excel VBA Sin Function for Degree Unit
Return Values for Excel VBA Sin Function for Degree Unit

Things to Keep in Mind

  • Since VBA already includes the Sin function, your project won’t need additional libraries or references.
  • The argument “number” must be written in radians. You can use the VBA function “Application.WorksheetFunction.Radians” to change degrees to radians.

Frequently Asked Questions

Q: Is it possible to use complex numbers with the Sin function?

A: No, only real numbers can be used with the Sin function.

Q: Can I determine a triangle’s angle using the Sin function given the lengths of its sides?

A: No, you would need to use one of the other trigonometric functions, such as Asin, Acos, or Atan, to determine the angle of a triangle given the lengths of its sides.

Conclusion

From this article, you have learned how to use the VBA Sin function in Excel to determine the sine values for two different units (radian and degree). These, in our opinion, will improve your professional work life somehow. 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! 

2 thoughts on “How to Use the Excel VBA Sin Function (2 Examples)”

  1. Heya! I’m at work browsing your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the fantastic work!

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Doc
Jump to Topics
SOLVED EXCEL
Scroll to Top