Custom Function in Excel PDF
Custom Function in Excel PDF
First make sure that we are working in a macro-enabled workbook (one of the Excel file types)
because we need to work with VBA code.
To create the custom (User defined) function in Excel:
1. Go to Microsoft Visual Basic Editor for Applications window (Press Alt + F11)
This gets us to the Visual Basic Editor, where VBA is written. OR
Click the Developer tab of the Ribbon > Visual Basic button.
If the Developer tab is not visible then check the Developer checkbox on the Customize Ribbon
tab of the Excel Options dialog box.
Excel Option > Customize Ribbon > Check Developer.
2. Choose InsertModule in the editor.
This bring us an empty code module in front. Now its time to create the custom excel function.
The example code is:
Public Function Add(number1 As Range, number2 As Double)
Add = number1 + number2
End Function
This function takes two arguments number1 and number2. The first argument, number1, is
value taken from another excel cell and the second argument, number2, is number.
And value must be assigned to the variable with same name as that of the function, which is
returned to the cell in which this function is used.
3. Save the function.
Macros and VBA programming can be saved only in a macro-enabled workbook.
4. Use the custom function
Now return to excel sheet and use the custom user defined function as standard excel function.