Using Custom Functions
Now you’re ready to use the new DISCOUNT function. Press Alt+F11 to switch to the worksheet shown in Figure 27-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.
In the first line of your VBA code, Function Discount(quantity, price), you indicated that the DISCOUNT function requires two arguments, quantity and price. When you call the function in a worksheet cell, you must include those 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 27-3.
Figure 27-3. This worksheet shows the result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access