+ Reply to Thread
Results 1 to 2 of 2

Thread: User Defined Functions Excel

  1. #1
    Registered User
    Join Date
    01-17-2012
    Location
    Orlando FL
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    17

    Question User Defined Functions Excel

    I'm frustrated with User Defined Functions in VBA. I still have no clue of code structure. WHen do you have a sub and when do you have a function?

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: User Defined Functions Excel

    A SUB is a macro that is called by a human or by another SUB. It's triggered on demand or by some event in the workbook.

    A FUNCTION is essentially a kind of SUB that when complete feeds the "result" back to where it was called from. If the FUNCTION is entered into a cell as a formula, the result appears in the cell. If the FUNCTION is called by another macro (SUB) then the result is fed back to that macro, supposedly so it can use that in its further activities.



    A simple example might be:

    A "sub" can be designed to drive your car to work.

    A "function" might be used to give YOU some information on how YOU can drive the car. The "sub" above might call a FUNCTION to find out how to turn on the car, the result is fed back to the "sub" and it turns on the car... then proceeds to the next step.
    Last edited by JBeaucaire; 01-26-2012 at 05:40 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ 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.2.0