• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / VBA / VBA pi – Get Value of pi Using Excel pi Worksheet Function

VBA pi – Get Value of pi Using Excel pi Worksheet Function

January 28, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  How to Get Column Letter from Number Using an Excel VBA Macro
  • 2.  VBA Tanh Worksheet Function – Find Hyperbolic Tangent of Number
  • 3.  VBA Atan2 Worksheet Function – Arctangent of Quotient of Two Numbers
  • 4.  VBA Atn – Find Arctangent and Inverse Tangent of Number
  • 5.  VBA Asin Worksheet Function – Find Arcsine and Inverse Sine of Number
  • 6.  VBA Acos Worksheet Function – Find Arccosine of Number
  • 7.  VBA Trig – Using Trigonometric Functions in VBA for Trigonometry
  • 8.  VBA Cos – Find Cosine of Number in Radians Using VBA Cos() Function
  • 9.  VBA Convert Radians to Degrees with WorksheetFunction.Degrees()
  • 10.  VBA Acosh Worksheet Function – Inverse Hyperbolic Arccosine of Number

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy