Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Module in Excel 2

Status
Not open for further replies.

enirwin

Mechanical
Joined
Feb 14, 2002
Messages
46
Location
US
I'm trying to create a custom function in Excel using a VBA module. My problem is that I can't get Pi to work. If I enter 3.14 my function works properly. If I use Pi I get an error. It seems to be using 0 for Pi.

For now, I'm using 3.14159265358979 for Pi, but I'd rather just use Pi. Can anyone help?

Thanks.
 
You need Excel.WorksheetFunction.Pi()

Example
Function test()
MsgBox (Excel.WorksheetFunction.Pi())
End Function

=====================================
Eng-tips forums: The best place on the web for engineering discussions.
 
That's it.

Thanks.
 
I recommend using a constant as follows

Const PI as Double= 3.14159265358979


Then you can use it in Functions

A=PI*D*D/4
 
You can also calculate it. PI=4*ATAN(1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top