11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 23: Function Procedure Basics 617<br />

[Public | Private][Static] Function name ([arglist]) [As type]<br />

[statements]<br />

[name = expression]<br />

[Exit Function]<br />

[statements]<br />

[name = expression]<br />

End Function<br />

The following list describes the elements in a Function procedure declaration:<br />

Public: Indicates that the function is accessible to all other procedures in all other<br />

modules in the workbook (optional).<br />

Private: Indicates that the function is accessible only to other procedures in the same<br />

module (optional). If you use the Private keyword, your functions won’t appear in the<br />

Insert Function dialog box and will not be shown in the <strong>Formula</strong> AutoComplete dropdown<br />

list.<br />

Static: Indicates that the values of variables declared in the function are preserved<br />

between calls (optional).<br />

Function: Indicates the beginning of a Function procedure (required).<br />

Name: Can be any valid variable name. When the function finishes, the result of the function<br />

is the value assigned to the function’s name (required).<br />

Arglist: A list of one or more variables that represent arguments passed to the function.<br />

The arguments are enclosed in parentheses. Use a comma to separate arguments.<br />

(Arguments are optional.)<br />

Type: The data type returned by the function (optional).<br />

Statements: Valid VBA statements (optional).<br />

Exit Function: A statement that causes an immediate exit from the function<br />

(optional).<br />

End Function: A keyword that indicates the end of the function (required).<br />

Choosing a name for your function<br />

Each function must have a unique name, and function names must adhere to a few rules:<br />

You can use alphabetic characters, numbers, and some punctuation characters.<br />

However, the first character must be alphabetic.<br />

You can use any combination of uppercase and lowercase letters.<br />

You can’t use a name that looks like a worksheet cell’s address (such as J21 or SUM100).<br />

Actually, Excel allows you to use such a name for a function, but the function returns a<br />

#REF! error.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!