Using PI in a macro

N

Nils Titley

I know PI can be used in a formula in for a cell. I am writing a macro to
provide the same formula while process other data.

When I try to use it, I get a compile error, sub or function not defined.

It is a complicated formula but (Cos(D1031 * Pi() / 180)......

Is there some thing I have to use PI?

Thanks
 
C

Chip Pearson

You can use Application.Pi. E.g,

(Cos(D1031 * Application.Pi() / 180)......


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

Dana DeLouis

When I try to use it (Pi() ), I get a compile error, sub or function not

Hi. You need to use "WorksheetFunction.Pi"
However, this looks terrible in a formula.
Here are some general ideas for using a variable.

Sub Demo1()
Debug.Print WorksheetFunction.Pi

Dim Pi, Deg
Pi = [Pi()]
Deg = [Pi()/180]

Debug.Print Pi
Debug.Print Sin(90 * Deg)
End Sub

If you have a little imagination, here is Character 0182 used as Pi.
Probably not useful though.

Sub Demo2()
Dim ¶ As Double 'Alt + 0182
¶ = [Pi()]
Debug.Print Cos(45 * ¶ / 180)
End Sub
 
N

Nils Titley

Thanks all for responding. I am using the Application.Pi(). It is working
but I will also try the others.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top