Consulting

Results 1 to 9 of 9

Thread: Sleeper: Creating own formula

  1. #1

    Sleeper: Creating own formula

    Hi,
    I am new to excell programming. I would like to know how to create my own custom formual by creating functions or procedures. I know how to create functions. My question is how can I add the custom function to be used as custom formula just like excell formula by entering = in a cell.

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi LK,

    To use the function in a worksheet, you have to either have that function code in a module of the worksheet you want to use it on, or in a module of an addin that is installed/active in excel.

    For example, though I know you know how to make functions, create a new workbook in excel and press alt-f11 to open the VBA editor. Right click within the vbaproject of that new workbook, go to Insert, then Module. In that module, paste the following:

    Function DoubleANumber(ByVal TheNumber As Double) As Double
     DoubleANumber = 2 * TheNumber
    End Function
    Close the VBA editor, and in a cell of that worksheet, enter =doubleanumber(5) and you'll see 10.
    As I said, if you have a custom add-in, or one that allows you to make changes, if you put that function in there too it will work, provided the add-in is installed.

    Matt

  3. #3

    Working but yet another question

    Hi,

    Thanks for your reply it is working. What it is not doing is that like excell formula, there is no intellisence for parameter prompt for user to properly use the formula. What is the way to prompt user with parameters along with formula and when we type just a few words of formula and it fill entierely just like excell formula.

    Please reply.

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    The only way that is possible is through an Add-In.

  5. #5
    I guess I just don't understand what you want. When you said "parameters", do you mean function arguments? The functions I have that require arguments show up in the formula list. When I press Enter, then I get the dialog box that prompts (so to speak) for each argument one at a time. I didn't do anything special to make that happen. It's best to name the arguments with names that are pretty much self-explanatory. You can add a few lines of explanatory information to be associated with the function too. I think you'll see where that can be done if you go through the procedure of recording a new macro by doing things on your worksheet. When you turn off the macro recording, they give you a chance to write some explanation of what the macro does.

  6. #6
    ok, I will try and let you know.

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    This came up a couple of days ago. See this thread for details and a link to Laurent Longre's site.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  8. #8
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Look in the cool tools section.

  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    ALe, the Cool Tools section has parry's add-in, not Laurent Longre's add-in. (I kind of hijacked the thread telling about another add-in - parry's.) I have them both, they're excellent.

Posting Permissions

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