CHAPTER 5Creating Function Procedures
Sub Procedures vs. Function Procedures
A VBA Function is a procedure that performs calculations and returns a value. You can use these functions in your Visual Basic for Applications (VBA) code or in worksheet formulas.
VBA enables you to create Sub procedures and Function procedures. You can think of a Sub procedure as a command that either the user or another procedure can execute. Function procedures, on the other hand, usually return a single value (or an array), just like Excel worksheet functions and VBA built-in functions. As with built-in functions, your Function procedures can use arguments.
Function procedures are versatile, and you can use them in two situations.
- As part of an expression in a VBA procedure
- In formulas that you create in a worksheet
In fact, you can use a Function procedure anywhere you can use an Excel worksheet function or a VBA built-in function. The only exception is that you can't use a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access