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?
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 theicon 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!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks