 # VBA Cos Function in Excel

VBA Cos function in Excel is categorized as Math(Mathematical) & Trig function. This is a built-in Excel and VBA Function. This function returns the cosine value of an angle of number in radians. The returned cosine value is between -1 and 1.

• Convert degrees to radians, multiply degrees with pi/180.

We can use this function in VBA and Excel. This function can be used in either procedure or function in a VBA editor window in Excel. This VBA Cos Function in any number of times in any number of procedures or functions. Let us learn what is the syntax and parameters of the Cos function, where we can use this Cos Function and real-time examples in Excel VBA.

## Syntax of VBA Cos Function

The syntax of the Cos Function in VBA is

`Cos(Number)`

The Cos function returns value is a Double data type.

#### Parameters or Arguments:

The Cos function has one argument in Excel VBA.
where
Number:The Number is a required parameter. It represents an angle in radians, which we want to find cosine value.

### Where we can apply or use VBA Cos Function?

We can use this Cos Function in VBA MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

### Example 1: Find the Cosine value(0)

Here is a simple example of the VBA Abs function. This below example returns the cosine value(0) of a number.

```'Find the Cosine value(0)
Sub VBA_Cos_Function_Ex1()

'Variable declaration
Dim iValue As Integer
Dim dResult As Double

iValue = 0

dResult = Cos(iValue)

MsgBox "The Cosine value of 0 is : "  & dResult, vbInformation, "VBA Cos Function"

End Sub
```

Output: Here is the screen shot of the first example output. ### Example 2: Find the Cosine value(60)

Here is a simple example of the VBA Abs function. This below example returns the cosine value(60) of a number.

```'Find the Cosine value(60)
Sub VBA_Cos_Function_Ex2()

'Variable declaration
Dim iValue As Integer
Dim dResult As Double

iValue = 60

dResult = Cos(iValue)

MsgBox "The Cosine value of 60 is : " & vbCrLf & dResult , vbInformation, "VBA Cos Function"

End Sub
```

Output: Here is the screen shot of the second example output. ### Example 3: Find the Cosine value(270)

Here is a simple example of the VBA Abs function. This below example returns the cosine value(270) of a number.

```'Find the Cosine value(270)
Sub VBA_Cos_Function_Ex3()

'Variable declaration
Dim iValue As Integer
Dim dResult As Double

iValue = 270

dResult = Cos(iValue)

MsgBox "The Cosine value of 270 is : " & vbCrLf & dResult , vbInformation, "VBA Cos Function"

End Sub
```

Output: Here is the screen shot of the third example output. #### Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

#### Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.