You want a user-defined function. I don't know if the current help file system has any good articles to introduce UDF's. They can be as simple or as complex as you feel you need. Key things to know about writing UDF's
1) UDF's cannot modify the spreadsheet environment!!! They cannot write data to cells, they cannot format anything. All they can do is receive arguments from the spreadsheet, perform the calculations, and return a value to the spreadsheet.
2) The best UDF's will receive all needed information from the argument list. This allows Excel to figure out where the function fits in the calculation dependency tree.
3) UDF's are stored in a regular module in VBA. If you have functions that you want available to all spreadsheets, you can store them in your personal workbook or in an add-in.
For the simple example you give, the UDF might look like
see if this tutorial helps http://office.microsoft.com/en-us/ex...996.aspx?CTT=1
Bookmarks