+ Reply to Thread
Results 1 to 15 of 15

formula for pi()

  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    formula for pi()

    How would one write a user-defined-function for calculating the Cross Section Inside Pipe Area?
    Can this be achieved?
    JS
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: formula for pi()

    Is there a specific part of building such a UDF that you need help with.

    I might suggest that you start with this tutorial that I wrote: http://www.excelforum.com/tips-and-t...uild-udfs.html This tutorial and the accompanying links will give you some basic ideas on how to structure a UDF and some of the debugging steps that I use to build a UDF.
    Then, visit your favorite geometry tutorial to make sure that you know and understand the mathematical formulas for cross section of pipe.
    Then, build your UDF. Be sure to pass appropriate arguments through the argument list.

    Let us know where you get stuck.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: formula for pi()

    In VBA

    Please Login or Register  to view this content.
    for a worksheet function, try =PI()
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: formula for pi()

    Thanks MrShorty

    I will read the tutorial and then see how i go

    Best Regards

    JS

  5. #5
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: formula for pi()

    Hi Mike

    Could you please explain how you would use in VBA

    Best regards

    JS

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: formula for pi()

    For your attached file, I wouldn't use VBA, I would use worksheet formulas to calculate the result.

    Responding to your thread title, my post was pointing out that there is a built-in worksheet function PI() that isn't available in VBA (Other than through the WorksheetFunction object). If you are working in VBA, I posted one of the many ways to calculate pi.

  7. #7
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: formula for pi()

    Thanking you

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: formula for pi()

    The goal is an easy example to show how to create and use a UDF.

    Most Engineers, prefer using diameter rather than radius which is your di/2 since r=d/2. That is because diameter can easily be measured. As an Engineer, I use diameter for that very reason, most of the time...

    Please Login or Register  to view this content.
    I normally measure 3 equidistant locations for diameter and average them.
    Last edited by Kenneth Hobson; 06-29-2016 at 10:57 AM.

  9. #9
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: formula for pi()

    Here's the UDF if you want it. It needs to be placed in a Module. Then you would call it like

    =Pipe_CS_Area(73)

    Please Login or Register  to view this content.
    Thanks to @mikerickson for the new way to calculate pi.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formula for pi()

    Why use a transcendental function to calculate a constant?

    Please Login or Register  to view this content.
    Last edited by shg; 06-29-2016 at 11:17 AM.
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: formula for pi()

    Quote Originally Posted by shg View Post
    Why use a transcendental function to calculate a constant?
    Because its a transcendental constant.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formula for pi()

    Not to your computer; it's a rational number (someInteger/2^something) whose value need not be calculated.

  13. #13
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: formula for pi()

    Like Mike said, there are several ways to set a value for pi. SHG's constant method is fine too.

    Like pi, the discussion has not been Vulgar. Pi history is certainly interesting. I do well to memorize 4 decimal places, much less 70,000. https://en.wikipedia.org/wiki/Pi

    It is a pet peeve of mine though when the best approximation of pi is not used. In the old days when slide rules ruled, that was fine. I still have one, somewhere. For kicks, it might be fun to dig it out and see if I can remember how I used it. https://en.wikipedia.org/wiki/Slide_rule

    The OP has his answer, and then some, so all is good.

  14. #14
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: formula for pi()

    22/7 is actually a very close approximation.

    =(22/7)/ PI() returns 1.000402499

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formula for pi()

    Or 245850922/78256779, which returns the same value as =PI()

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 06-06-2014, 03:34 PM
  2. how to hide formula in formula box, view lookup result in formula box?
    By vengatvj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2013, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1