Friday, August 12, 2016

How to use the COS Function (WS,VBA)

Description

The Microsoft Excel COS function returns the cosine of an angle.

Syntax

The syntax for the COS function in Microsoft Excel is:
COS( number )

Parameters or Arguments

number
A numeric value used to calculate the cosine.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • Worksheet function (WS)
  • VBA function (VBA)

Example (as Worksheet Function)

Let's look at some Excel COS function examples and explore how to use the COS function as a worksheet function in Microsoft Excel:
Microsoft Excel
Based on the Excel spreadsheet above, the following COS examples would return:
=COS(A1)
Result: 0.980066578

=COS(A2)
Result: 0.939372713

=COS(A3)
Result: -0.999964658

=COS(200)
Result: 0.487187675

Example (as VBA Function)

The COS function can also be used in VBA code in Microsoft Excel.
Let's look at some Excel COS function examples and explore how to use the COS function in Excel VBA code:
Dim LNumber As Double

LNumber = Cos(210)
In this example, the variable called LNumber would now contain the value of -0.883877473.