Subscriber only lesson.
Sign up to this course to view this lesson.
About this lesson
Calling a UDF from a worksheet and from VBA.
Download this lesson’s exercise file.Calling a User Defined Function (UDF).xlsm
Calling a User Defined Function (UDF)
Using a UDF in your work
When to use
When you wish to call a UDF from a worksheet or from VBA
Calling UDF's from a Worksheet
- To call a UDF from a worksheet, just type =FunctionName() in the worksheet
- Any required parameters will need to be included
- Functions that use values/ranges as inputs will recalculate when their precedents change
- Other functions may not recalculate upon change. This can be fixed by adding Application.Volatile to the function code
Calling UDF's from VBA
- To call a UDF, create a variable then set the variable equal to the function
- Sample code:
Dim sFuncResult As String
sFuncResult = myFunction("input if required")
Hints & tips
- Functions that return a number, text, date, yes/no, or true/false result can be called from an Excel worksheet or VBA
- Functions that return objects, ranges or collections of data can only be called from VBA
Lesson notes are only available for subscribers.