Microsoft Office Tutorials and References
In Depth Information
Figure 24-1: A simple VBA function displayed in a code window.
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 follow-
ing 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 for-
mula 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:
Search JabSto ::




Custom Search