The VBA COS function is listed under the math category of VBA functions. When you use it in a VBA code, it returns the cosine of a supplied angle. In simple words, a cosine of an angle is the length of the adjacent side of a right triangle, divided by the length of the hypotenuse which this function returns.
- Number: The angle value for which you want to calculate the cosine.
To practically understand how to use VBA COS function, you need to go through the below example where we have written a vba code by using it:
Sub example_COS() Range("B1").Value = Cos(Range("A1")) End Sub
In the above example, we have used the value from cell A1 (12) and then we have used the COS function to get the cosine of a supplied angle and it has returned 0.843853958732492 in the result.
- If the value specified is a value other than a number or a string which can’t be recognized as a number, VBA will return the run-time 13 error.
- You can multiply the result returned by the COS with pi/180 to convert it into radians and 180/pi to convert it into degrees.
ABS | ATN | EXP | FIX | INT | LOG | RND | ROUND | SGN | SIN | SQR | TAN