Type Code
You will need to be familiar with VBA code to complete this step in your own work. The basic syntax of User Defined Function is:
Function myfunctionname (arguments) return type
Myfunctionname = calculation
End Function
Adding “Public” to Function tells Excel to list your User Defined Function in the Insert Function dialog box.
Here is simple sample code for our Triangle Area Function.
Public Function TRIAREA(number1, number2)
TRIAREA = (number1 * number2) / 2
End Function

Hint! If your variables are very specific – such as in our example, number1 will always be the Base of our triangle, and number2 will always be the Height – you can give them specific names to help you when you are completing the function in your workbook:

When you are finished writing the code, click the save button or hit Ctrl+S to save your custom function to the workbook. Note that you will only be able to use it in the workbook in which it was saved, it is not a global function.
Close the VBA editor.
Use Your User Defined Function
Back in your Excel workbook, place your cursor in the place where you wish to insert the custom function:
1. Click Insert Function on the Formulas tab.
2. In the Insert Function dialog box, select User Defined from the “select a category” dropdown list. You should see the name you gave your function. In this example we see TRIAREA.
3. Select the function, then click OK.
4. Fill out the Function Arguments dialog box and click OK.
