How do I... Create a user-defined function in Microsoft Excel
Source: Mark W. Kaelin
Sometimes you find yourself in a situation where you can't get Microsoft Excel to do exactly what you want it to do without coding a complicated formula over and over again. Microsoft Excel allows users to create their own user-defined functions. Using the power of Visual Basic for Applications (VBA), you can code complicated formulas only once and use them again and again in a user-defined function. These functions can be used just like any built-in function already available in Excel. Here's how you create one.
This download is also available as a TechRepublic article.