Using Custom Functions

Now you’re ready to use the new DISCOUNT function. Press Alt+F11 to switch to the worksheet shown in Figure 28-1. Select cell F9, and type the following:

=DISCOUNT(C9,D9)

Excel calculates the 10 percent discount on 200 units at $47.50 per unit and returns $950.00.

The first line of your VBA code, Function Discount(quantity, price), indicates that the DISCOUNT function requires two arguments, quantity and price. When you call the function in a worksheet cell, you must include these two arguments. In the formula =DISCOUNT(C9,D9), C9 is the quantity argument, and D9 is the price argument. Now you can copy the DISCOUNT formula to F10:F15 to get the worksheet shown in Figure 28-3.

Figure 28-3. This worksheet shows the result of the ...

Get Microsoft® Excel® 2010 Inside Out now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.