A function with no argument

Like Sub procedures, Function procedures need not have arguments. For example, Excel has a few built-in worksheet functions that don't use arguments, including RAND, TODAY, and NOW.

Here's a simple example of a function with no arguments. The following function returns the UserName property of the Application object. This name appears in the Options dialog box (General tab). This simple but useful example shows the only way you can get the user's name to appear in a worksheet formula:

Function User()

' Returns the name of the current user

User = Application.UserName End Function

When you enter the following formula into a worksheet cell, the cell displays the current user's name:

As with the Excel built-in functions, you must include a set of empty parentheses when using a function with no arguments.

0 0

Post a comment