Astra

Excel VBA Acos Function (ArcCos or Inverse Cos) (3 Examples)

Estimated reading: 4 minutes
Excel VBA Acos Function to Find Values in Degrees

The Acos function in Visual Basic for Applications (VBA) calculates the arccosine (inverse cosine) of a given angle in radians. The cosine of the angle is the only argument required for the Acos function, which then returns a value in radians between 0 and pi.

Purpose of the VBA Acos Function

To find the radian angle of a cosine value.

Syntax of the VBA Acos Function

WorkSheetFunction.Acos(Arg1 As Double)
Syntax of the VBA Acos Function
Syntax of the VBA Acos Function

Arguments of the VBA Acos Function

ArgumentExplanation
Arg1 As DoubleThe cosine value for which the radian angle is calculated

Example #1: Get Radian Angles with the VBA Acos Function

The VBA Acos function by default calculates the arccosine or inverse cosine values in radians. But, this function cannot perform for a range of values. So, we will apply a For Loop with the VBA Acos function to apply the function to each cell in a range. 

  • Copy the codes and paste them into your Module.
Sub Acos_Radian()

Dim xCell As Range

'Apply For Loop with Acos Function

For Each xCell In Range("B4:B8")

  xCell.Offset(0, 1) = WorksheetFunction.Acos(xCell.Value)

Next xCell

End Sub
VBA Acos Function to Find the Radian Angles
VBA Acos Function to Find the Radian Angles
  • After running the code, you will get the following output with the radian values for the Acos function.
Return Values with Radian Angles
Return Values with Radian Angles

Example #2: Get Degree Angles with VBA Acos & Pi Functions

The VBA Acos function does not return the values in degrees. To get the degree angles, we will apply the general formula for degree conversion. 

degree = (radian*180) / Pi)  'Pi = 3.14159265358979
  • Copy the codes and paste them into your Module.
Sub Acos_Degree1()

Dim Pi As Long

Dim xCell As Range

Dim xCellValue As Range

Dim Acos_Degree As Range

'Apply For Loop with Acos function

For Each xCell In Range("B4:B8")

   xCell.Offset(0, 1) = WorksheetFunction.Acos(xCell.Value)

Next xCell

Pi = 3.14159265358979

Set xCellValue = Range("C4:C8")

For Each xCellValue In Range("C4:C8")

'Offset function for (0, 0) value will place the result in the same column

    xCellValue.Offset(0, 0) = (xCellValue * 180) / 3.14159265358979

Next xCellValue

End Sub
VBA Code to Find Degree Angles for Cosine values
VBA Code to Find Degree Angles for Cosine values
  • After running the code, you will get the following output values in degrees.
Return Values with Degree for Cosine Values
Return Values with Degree for Cosine Values

Example #3: Get Degree Angles with VBA’s Acos Function & WorkSheetFunction.Degrees Function

Similar to Example 2, we will apply the VBA Degrees function to get the inverse cosine values in degrees. The VBA Degrees function is a built-in WorkSheetFunction to convert radians into degrees.

  • Copy the codes and paste them into your Module.
Sub Acos_Degree2()

Dim xCell As Range

Dim xCellValue As Range

Dim Acos_Degree As Range

'Apply For Loop with Acos function

For Each xCell In Range("B4:B8")

   xCell.Offset(0, 1) = WorksheetFunction.Acos(xCell.Value)

Next xCell

Set xCellValue = Range("C4:C8")

For Each xCellValue In Range("C4:C8")

'Offset function for (0, 0) value will place the result in the same column

    xCellValue.Offset(0, 0) = Application.WorksheetFunction.Degrees(xCellValue.Value)

Next xCellValue

End Sub
  • After running the code, you will get the following output values in degrees.

Things to Keep in Mind

  • The function returns a radian value in the range of 0 and pi.
  • For some input values, such as those outside the cosine argument’s range of -1 to 1, the Acos function may return errors. 
  • It is a built-in feature of VBA and doesn’t call for the importation of any extra libraries or modules.

Frequently Asked Questions

Q1: What occurs if the Acos function’s input value falls outside of the range of -1 to 1?

  • The Acos function will return a #NUM! Error if the input value is outside the range of -1 to 1.

Q2: Can the Acos function produce negative results?

  • The answer is that the Acos function can produce negative values, which correspond to angles in the third or fourth quadrant of the unit circle.

Q3: Is the Acos function case-sensitive?

  • No, the Acos function is not case-sensitive in VBA, so you can use either uppercase or lowercase letters to call it.

Conclusion

The VBA Acos function is useful in a variety of mathematical and scientific applications, such as calculating angles in trigonometry or calculating probabilities in statistics. 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! 

3 thoughts on “Excel VBA Acos Function (ArcCos or Inverse Cos) (3 Examples)”

  1. What i don’t realize is in trith how you are
    now not really a lot more well-preferred than you
    might bee right now. You aree so intelligent.
    You know therefore considerably with regards to this matter, produced me
    in my opinion believe it from a lot of varied angles. Its lik
    women and men are not involved unlkess it iis one thing to do with Woman gaga!

    Your personal stuffs great. Always handle it up!

    my blog post https://vavadacasino.mystrikingly.com/

  2. I bblog often and I seriousl thank youu for your content.

    The article haas truly peaked my interest. I am going to bookmark your site and keep chewcking for
    new details about once per week. I opted in for yolur RSS feed too.

    Here is my web-site … Mellisa

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