Writing custom formulaes for excel using VBA
First open the visual basic editor ( In excel 2003 it is available from Tools>Macros>visual basic editor. In excel 2007 it should be enabled from the excel options menu, then invoke using Alt+F11 or from the developer ribbon)
Type the function as shown in the screen shot.
If it is necessary to create a library of formulaes, then save the exec as an excel addin. The put the addin in the "C:\Documents and Settings\