Professional Documents
Culture Documents
You
can insert it in a formula by choosing FormulasFunction
LibraryInsert Function or by clicking the Insert Function Wizard
icon to the left of the formula bar. Either of these actions displays the
Insert Function dialog box. In the Insert Function dialog box, your
custom functions are located, by default, in the User Defined category.
You can also nest custom functions and combine them with other
elements in your formulas. For example, the following formula nests
the REMOVEVOWELS function inside Excel's UPPER function. The
result is the original string (sans vowels), converted to uppercase.
=UPPER(REMOVEVOWELS(A1))
Figure 8-2 shows text entered into an input box, and the result
End Function
Note that the procedure starts with the keyword Function, rather than
Sub, followed by the name of the function (REMOVEVOWELS). This
custom function uses only one argument (Txt), enclosed in
parentheses. As String defines the data type of the function's return
value. Excel uses the Variant data type if no data type is specified.
The second line is an optional comment that describes what the
function does. This line is followed by a Dim statement, which
declares the variable (i) used in the procedure as type Long.
Function Procedures
A Function procedure has much in common with a Sub procedure.
(For more information on Sub procedures, see Chapter 7.)