Looking at Function procedures

Every Function procedure starts with the keyword Function and ends with an End Function statement. Here's a simple example:

Function CubeRoot(number) CubeRoot = number A (1 End Function

This function, named CubeRoot, takes one argument (named number), which is enclosed in parentheses. Functions can have any number of arguments or none at all. When you execute the function, it returns a single value — the cube root of the argument passed to the function.

VBA allows you to specify what type of information is returned by a Function procedure. Chapter 7 contains more information on specifying data types.

You can execute a Function procedure in only two ways. You can execute it from another procedure (a Sub or another Function procedure) or use it in a worksheet formula.

You can't use the Excel macro recorder to record a Function procedure. You must manually enter every Function procedure that you create.

0 0

Post a comment