Locked lesson.
About this lesson
Creating a UDF to return the user name.
Exercise files
Download this lesson’s exercise file.
Creating User Defined Functions (UDFs).xlsm22.2 KB
Quick reference
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
Instructions
UDF Syntax
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>
End Function
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.