Microsoft Office Excel
Jump to navigation
Jump to search
User Defined Functions in VBA
- Reference: [1]
- Example of function
Function RectangleArea(Height As Double, Width As Double) As Double
RectangleArea = Height * Width
End Function
- Where to put the code
- The UDF must be placed in a standard code module (not in one of the
Sheet
modules and not in theThisWorkbook
module). - To create a standard module: go to Insert menu, and choose Module.
- Rename the module by pressing F4 and display the Properties, and change the Name property.
- Calling the UDF from the same workbook
- Simply use the function name. For instance, type in cell A3:
=RectangleArea(A1,A2)