To get the value of pi in VBA, the easiest way is use the Excel worksheet function **Pi**. WorksheetFunction.Pi returns the value 3.1415926535897939.

```
Debug.Print WorksheetFunction.Pi
'Output:
3.1415926535897939
```

In VBA, we can easily get the value of pi for use in trigonometry with the VBA math functions.

Unfortunately, VBA doesn’t have pi as a property or function, but we can use the Excel worksheet function Pi to get the value of pi.

For example, let’s say we want to find the sine of a number. The VBA sin() function takes a number in radians and then finds the sine of the number.

To find the sine of a number, we can use pi to make our lives easy.

To get the value of pi in your VBA code, you just need to call the worksheet function **Pi** as shown below.

```
Debug.Print WorksheetFunction.Pi
'Output:
3.1415926535897939
```

Then, if you want to use it like in our example with finding the sine of a number, you can use the pi constant in the following way.

```
Debug.Print Sin(WorksheetFunction.Pi/3)
'Output:
0.8660254037844386
```

Hopefully this article has been helpful for you to understand how to find the value of pi from the Excel worksheet function Pi in VBA.

## Leave a Reply