You have to use VBA for making User Defined Function in Excel (UDF).
Click on Developers tab in the ribbon (Excel 2007) then click on Visual Basic or use Alt+F11.
Then insert a new module by Insert->Module and write your function there.
The functions will be inlcuded Insert Function dialog box in "User Defined" category.
To use the functions in another excel documents you must save them in your own add-in by saving the file as add-in file .xla or .xlam for Excel 2007. Then load the add-in by Start->Excel Options->Add-ins->Go.