Microsoft Office Tutorials and References
In Depth Information
About Function Procedures
If you entered the VBA code correctly, the Function procedure executes, and your name
displays (in uppercase characters) in the cell.
If your formula returns an error, make sure that the VBA code for the USER function is in a
VBA module (and not in a module for a Sheet or ThisWorkbook object). Also, make sure
that the module is in the project associated with the workbook that contains the formula.
When Excel calculates your worksheet, it encounters the USER custom function, and then goes
to work following the instructions. Each instruction in the function is evaluated, and the result is
returned to your worksheet. You can use this function any number of times in any number of cells.
You’ll find that this custom function works just like any other worksheet function. You can insert
it into a formula by using the Insert Function dialog box, and it also appears in the Formula
AutoComplete drop-down list as you type it in a cell. In the Insert Function dialog box, custom
functions appear (by default) in the User Defined category. As with any other function, you can
use it in a more complex formula. For example, try this:
=”Hello “&USER()
Or use this formula to display the number of characters in your name:
=LEN(USER())
If you don’t like the fact that your name is in uppercase, edit the procedure as follows:
Function USER()
‘ Returns the user’s name
USER = Application.UserName
End Function
After editing the function, reactivate Excel and press F9 to recalculate. Any cell that uses the
USER function displays a different result.
About Function Procedures
In this section, I discuss some of the technical details that apply to Function procedures. These
are general guidelines for declaring functions, naming functions, using custom functions in
formulas, and using arguments in custom functions.
Declaring a function
The official syntax for declaring a function is as follows:
 
Search JabSto ::




Custom Search