Microsoft Office Tutorials and References
In Depth Information
About Function Procedures
[Public | Private][Static] Function name ([arglist]) [As type]
[statements]
[name = expression]
[Exit Function]
[statements]
[name = expression]
End Function
The following list describes the elements in a Function procedure declaration:
h Public : Indicates that the function is accessible to all other procedures in all other
modules in the workbook (optional).
h Private : Indicates that the function is accessible only to other procedures in the same
module (optional). If you use the Private keyword, your functions won’t appear in the
Insert Function dialog box and will not be shown in the Formula AutoComplete
dropdown list.
h Static : Indicates that the values of variables declared in the function are preserved
between calls (optional).
h Function : Indicates the beginning of a Function procedure (required).
h Name : Can be any valid variable name. When the function finishes, the result of the
function is the value assigned to the function’s name (required).
h Arglist : A list of one or more variables that represent arguments passed to the
function. The arguments are enclosed in parentheses. Use a comma to separate arguments.
(Arguments are optional.)
h Type : The data type returned by the function (optional).
h Statements : Valid VBA statements (optional).
h Exit Function : A statement that causes an immediate exit from the function
(optional).
h End Function : A keyword that indicates the end of the function (required).
Choosing a name for your function
Each function must have a unique name, and function names must adhere to a few rules:
h You can use alphabetic characters, numbers, and some punctuation characters.
However, the first character must be alphabetic.
h You can use any combination of uppercase and lowercase letters.
h You can’t use a name that looks like a worksheet cell’s address (such as J21 or SUM100).
Actually, Excel allows you to use such a name for a function, but the function returns a
#REF! error.
 
Search JabSto ::




Custom Search