# How to Create a Custom Function in Excel

Excel functions are actually shortcuts to more complex calculations. Like a macro is to a series of steps, a function is to a longer equation. While Excel is packed full of functions, you may find that you have proprietary formulas that you use regularly that would be useful as a function shortcut.

Advanced Excel users who are comfortable with creating and editing macros will find creating custom functions a snap. Even those who aren’t that familiar with VBA code can follow the steps below and create useful shortcuts to their calculations. This article will show how to create a very simple custom function (area of a triangle) to demonstrate the steps. You will have to figure out the math on your own!

Because custom functions use VBA, your file must be saved as a .xlsm Macro-enabled workbook.

Follow the steps below in a new, clean macro-enabled workbook of your own, or download 06-Custom Functions.xlsm to see the completed user defined function.

A function creates a calculation based on variables input at the time the function is used. To create your custom function, you will first need to identify the arguments needed in your function. We are going to create a function to quickly calculate the area of a triangle: Area = Base times Height divided by 2, or A=BH/2. Our arguments will be the base and the height.

Open Visual Basic Editor

Hit Alt + F11 or click the Visual Basic button the Developer tab.

Choose Insert > Module in the VBA editor:

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. When you are finished writing the code, save the function and close the editor.

Public Function TRIAREA(number1, number2)
TRIAREA = (number1 * number2) / 2
End Function