+ Reply to Thread
Results 1 to 12 of 12

Creating Custom Functions

  1. #1
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    922

    Creating Custom Functions

    I tried to create a custom function named "AddTwo" which add two arguments but It won't work.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by zanshin777; 10-21-2015 at 06:35 AM.

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

    Re: Creating Custom Functions

    I don't see any code anywhere in your project.
    For a UDF like, that I would put the code into a normal module (not a sheet's code module or the ThisWorkbook module or a Class module)

    Once the code is in the module, the custom function, called a UDF (User Defined Function), can be used in a worksheet formula like the one in Sheet1!H6 of the attached.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    10-10-2015
    Location
    Hoboken, Antwerp, Belgium
    MS-Off Ver
    2010
    Posts
    93

    Re: Creating Custom Functions

    Hi,

    Put this function in a modula, and you can call it after you've saved your workbook before using the function.
    You didn't specify the kind of variable you want to be returned.

    Please Login or Register  to view this content.
    Greetings,

    Cheetahke

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2403 Win 11 Home 64 Bit
    Posts
    23,811

    Re: Creating Custom Functions

    @zanshin777

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    922

    Re: Creating Custom Functions

    I edited the thread.

  6. #6
    Registered User
    Join Date
    10-10-2015
    Location
    Hoboken, Antwerp, Belgium
    MS-Off Ver
    2010
    Posts
    93

    Re: Creating Custom Functions

    Hi,

    You can try this:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    922

    Re: Creating Custom Functions

    It won't work. #VALUE error.

  8. #8
    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: Creating Custom Functions

    Post a workbook with the UDF installed and an example that shows an error.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    922

    Re: Creating Custom Functions

    Sorry. It was because I use "," rather than ";"

  10. #10
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    922

    Re: Creating Custom Functions

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Why Is there "As Double" in into line? (So, There isn't a variable. Is It?)

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

    Re: Creating Custom Functions

    I am not certain exactly what your question is. The only use of "As Double" in your code is to designate the data type for the function value. The function is technically not a "variable". However, like a variable, a function has a data type, and we, as programmers, can explicitly declare that data type so that VBA will generate errors if we mistakenly try to assign incorrect data to the function, or if we try to assign the function's result to a variable of the wrong data type. Explicitly declaring a function's data type has many of the same advantages (and limitations) as explicitly declaring a variable's data type in a Dim statement.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: Creating Custom Functions

    The line
    Please Login or Register  to view this content.
    is saying that the value returned by function SumArray will be data type Double.

+ 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: 6
    Last Post: 03-17-2015, 01:35 AM
  2. Need help with creating help files for custom VB excel 10 functions
    By DavidVentura in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-25-2013, 02:16 AM
  3. custom functions
    By stephenp12 in forum Excel General
    Replies: 1
    Last Post: 08-16-2011, 12:34 PM
  4. AddIn With custom functions - Functions not working in Excel2010
    By brum17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2011, 08:25 AM
  5. Custom tool tip for custom functions
    By usr789 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2007, 02:09 PM
  6. [SOLVED] Custom functions or VBA functions for Avg, Std, Min, Max?
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2006, 06:00 AM
  7. Using custom functions within custom validation
    By Neil in forum Excel General
    Replies: 4
    Last Post: 12-14-2005, 06:45 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