The primary effect of a function is to behave like a variable, except the function must do some processing whereas a variable can’t do any processing. One other MAJOR difference is that a macro function MUST NOT do anything that changes anything on a worksheet!! A function can otherwise do just about any kind of processing that a procedure can. It MUST however execute a statement that returns a value. For example, if you write a function named “GetThisSheetName”, somewhere in the code you MUST have a statement something like this:
GetThisSheetName = “Name of Sheet”
and that statement must be executed before exiting the function. Then, if used in a worksheet formula, you might write something like:
= Call GetThisSheetName()
Note that you MUST use parentheses following a function name that’s referenced in a formula. When used in a macro, the function name does not require the parens and you don’t need the “Call”. I suggest you look at help for the rules about arguments.
A procedure can return one or more values by using arguments. Normally arguments are used to pass information “to” a macro procedure, but you can use an argument to return a value ”from” the procedure to the caller if convenient.
One other thing to consider is results of an error that occurs in a function. Since a function MUST always return a value, you should provide a returned value that tells the calling routine a disaster has occurred. If your function normally returns a positive integer as a value, then you could return -1 if an error occurs.
HTH, Sid