30.04.2017 Views

4523756273

Create successful ePaper yourself

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

338<br />

Part V: Putting It All Together<br />

Notice that the four commission rates are declared as constants, rather than<br />

hard-coded. This makes it very easy to modify the function if the commission<br />

rates change.<br />

After you define this function in a VBA module, you can use it in a worksheet<br />

formula. Entering the following formula into a cell produces a result of 3,000.<br />

The amount of 25000 qualifies for a commission rate of 12 percent:<br />

=Commission(25000)<br />

Figure 20-1 shows a worksheet that uses the Commission function in formulas<br />

in column C.<br />

Figure 20-1:<br />

Using the<br />

Commission<br />

function in a<br />

worksheet.<br />

A function with two arguments<br />

The next example builds on the preceding one. Imagine that the sales manager<br />

implements a new policy to reward long-term employees: The total commission<br />

paid increases by 1 percent for every year the salesperson has been<br />

with the company.<br />

I modified the custom Commission function (defined in the preceding section)<br />

so that it takes two arguments, both of which are required arguments.<br />

Call this new function Commission2:<br />

Function Commission2(Sales, Years)<br />

‘ Calculates sales commissions based on years in service<br />

Const Tier1 As Double = 0.08<br />

Const Tier2 As Double = 0.105<br />

Const Tier3 As Double = 0.12<br />

Const Tier4 As Double = 0.14

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

Saved successfully!

Ooh no, something went wrong!