+ Reply to Thread
Results 1 to 8 of 8

Pi not defined?

  1. #1
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Pi not defined?

    XL2007, sp1:

    In a VBA module doing some trigonometry, I want to use the value of pi. Yet when I compile, Pi is highlighted as "variable not defined", although it is listed as an available worksheet function. Pi(), when compiled, returns sub or function not defined.

    And the workaround is...?

    [and searching on pi doesn't help. sorry.]

    TIA.

    George
    Last edited by geoB; 03-24-2009 at 10:48 PM.

  2. #2
    Forum Contributor
    Join Date
    03-12-2009
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: Pi not defined?

    You could just dump your formula to a worksheet cell have it calculate, then pull the result back into the code. Just a thought.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pi not defined?

    Perhaps you mean

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Re: Pi not defined?

    My eventual solution:

    Please Login or Register  to view this content.
    , where value was pasted from a cell using =pi().

    So it can be used throughout the module.

    g

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pi not defined?

    That makes sense but to reiterate you can just use Application.Pi, the below

    Please Login or Register  to view this content.
    is not a valid VBA expression... ie you were trying to use Native XL syntax in VBA which isn't going to work I'm afraid unless encased within an Evaluate call, eg:

    Please Login or Register  to view this content.
    Or as outlined using VBA syntax, either of:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hopefully this will help you as you move forward and use other Native Functions directly from VBE.

  6. #6
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Re: Pi not defined?

    Forgive my ignorance of VBE, but wouldn't
    Please Login or Register  to view this content.
    be required in each procedure needing pi? By placing a constant in the module declarations I get to use it in all procedures in the module without further ado. Is this method not recommended for some reason?

    g

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pi not defined?

    If you read my post you'll note I first said:

    "That makes sense"
    I should perhaps have clarified that this related to using a Public Constant....

    I was merely trying to make a point re: your initial post / question and how you can / should handle XL's native worksheet functions when calling from VBA ... plainly I'm failing in my objective so I shall not muddy the waters further
    (confirmed by the example you used in your last post... ie the only one I posted that I said wouldn't work!)

  8. #8
    Registered User
    Join Date
    03-05-2009
    Location
    6500' in the Sierra Nevada
    MS-Off Ver
    Office 2007, 2010
    Posts
    74

    Re: Pi not defined?

    Point taken, with apologies for my granite-like density.

    g

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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