+ Reply to Thread
Results 1 to 10 of 10

New to User Defined Functions....stumped.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2011
    Posts
    6

    New to User Defined Functions....stumped.

    I am trying to implement a function which calls excel function Beta.dist. A simplified example of what I am trying to do is:

    Function ReturnBeta(L,a,b)
        ReturnBeta = BETA.DIST(L, a, b, 1)
    End Function
    When I try to implement this function, I get the error message:
    " Compile Error: Sub or Function not defined"

    ? I'm stumped.
    Last edited by jeffreybrown; 02-01-2013 at 07:52 PM.

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

    Re: New to User Defined Functions....stumped.

    You access excel's function through the worksheetfunction object http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2011
    Posts
    6

    Re: New to User Defined Functions....stumped.

    So I tried that...modified my code to read

    ReturnBeta = Application.Worksheetfunction.Beta.Dist(L,a,b,1)
    ...and now get message

    "Method or Data Member not found"

    I also tried renaming the function as

    Application.worksheetfunction.betadist()
    No luck
    Last edited by jeffreybrown; 02-01-2013 at 07:53 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: New to User Defined Functions....stumped.

    Try Beta_Dist.
    If posting code please use code tags, see here.

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

    Re: New to User Defined Functions....stumped.

    Not sure what to tell you. This
    testbeta = Application.WorksheetFunction.BetaDist(x, a, b) 'x=.5,a=.5,b=.1
    worked just fine for me. Double check for typos, spelling errors, invalid arguments, correct number of arguments, etc.

  6. #6
    Registered User
    Join Date
    08-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2011
    Posts
    6

    Re: New to User Defined Functions....stumped.

    OK. It's even weirder then that. I hope I can describe it: I am trying to evaluate the cumulative distribution function, and so, per the syntax for the Beta.Dist function, there should be a fourth argument supplied to the BetaDist Function, being logical TRUE. Now, if I pass the first three variables and TRUE to the Application.Worksheetfunction.BetaDist(x,a,b,1), the function evaluates to "#VALUE." If I pass the first three variables and FALSE to the function, I get a result, which is the same result as using the Beta.Dist function in Excel but with the fourth argument set to TRUE - eg, I am only getting an evaluated function if I specify FALSE to the UDF, but that result is the same as supplying the same variables and TRUE to the excel function.
    Last edited by jeffreybrown; 02-01-2013 at 07:53 PM.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: New to User Defined Functions....stumped.

    If you use BETA_DIST there's a 4th argument.

  8. #8
    Registered User
    Join Date
    08-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2011
    Posts
    6

    Re: New to User Defined Functions....stumped.

    Yes, thanks... found out about Beta_Dist, but got a weird error trying to implement that. In looking on the web, it looks like the BetaDist function only evaluates to the *** function, and hence explains the error message and the weird properties.

    This is completely weird and typically Microsoftian.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: New to User Defined Functions....stumped.

    Both BetaDist and Beta_Dist worked fine for me in a function.

    How exactly did you use them?

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: New to User Defined Functions....stumped.

    @gblasius,

    Administrative Note:
    • Please follow Forum Rule #3 and use code tags.
    • Added for you this time, but please use them in the future…Thanks.
    HTH
    Regards, Jeff

+ 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