About this lesson
Creating a UDF to return the user name.
Download this lesson’s exercise file.Creating User Defined Functions (UDFs).xlsm
Creating User Defined Functions (UDFs)
Defining your own functions in VBA
When to use
When you want to create a function for use in VBA code, or mathematics that Excel doesn't already have
Function myFunc (<Var1> As <DataType>) As <DataType>
'Code to do whatever the UDF does
'Set function equal to its result
myFunc = <value/object/property from the UDF from above>
Hints & tips
- The data type MUST be declared for the function
- Although not required, it is highly recommended to declare the data types for parameters
Lesson notes are only available for subscribers.