18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Part VI<br />

Programming Excel with VBA<br />

Inserting Custom Functions<br />

Excel’s Insert Function dialog box is a handy tool that enables you to choose a worksheet function; you even<br />

can choose one of your custom worksheet functions. After you select a function, the Function Arguments<br />

dialog box prompts you for the function’s arguments.<br />

Function procedures that are defined with the Private keyword do not appear in the Insert<br />

Function dialog box. So if you create a function that will be used only by other VBA procedures,<br />

you should declare the function using the Private keyword.<br />

NOTE<br />

You also can display a description of your custom function in the Insert Function dialog box. To do so, follow<br />

these steps:<br />

1. Create the function in a module by using the VB Editor.<br />

2. Activate Excel.<br />

3. Choose Developer ➪ Code ➪ Macros.<br />

Excel displays its Macro dialog box.<br />

4. In the Macro dialog box, type the name of the function in the box labeled Macro Name.<br />

Notice that functions don’t normally appear in this dialog box, so you must enter the function<br />

name yourself.<br />

5. Click the Options button. Excel displays its Macro Options dialog box. (See Figure 40.3.)<br />

6. Enter a description of the function and then click OK. The Shortcut key field is irrelevant for<br />

functions.<br />

The description that you enter appears in the Insert Function dialog box.<br />

FIGURE 40.3<br />

Entering a description for a custom function. This description appears in the Insert Function dialog box.<br />

Custom functions are listed under the User Defined category.<br />

Figure 40.4 shows the Function Arguments dialog box, which prompts the user to enter arguments for a<br />

custom function.<br />

712

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!