0% found this document useful (0 votes)
12 views

Sub Procedures Versus Function Procedures: in This Chapter

This chapter discusses creating function procedures in VBA. It explains the difference between sub procedures and function procedures, with functions returning a value that can be used in VBA code or worksheet formulas. The chapter will cover creating custom functions, using function arguments, debugging functions, and more. It provides examples of functions that emulate Excel functions like SUM and enable working with pre-1900 dates.

Uploaded by

Rogerio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Sub Procedures Versus Function Procedures: in This Chapter

This chapter discusses creating function procedures in VBA. It explains the difference between sub procedures and function procedures, with functions returning a value that can be used in VBA code or worksheet formulas. The chapter will cover creating custom functions, using function arguments, debugging functions, and more. It provides examples of functions that emulate Excel functions like SUM and enable working with pre-1900 dates.

Uploaded by

Rogerio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 8: Creating Function

Procedures
In This Chapter
Understanding the difference between Sub
procedures and Function procedures
Creating custom functions
Looking at Function procedures and function
arguments
Creating a function that emulates Excel's SUM
function
Using functions that enable you to work with pre1900 dates in your worksheets
Debugging functions, dealing with the Insert
Function dialog box, and using add-ins to store
custom functions
Calling the Windows Application Programming
Interface (API) to perform otherwise impossible
feats

Sub Procedures versus 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 that you can use
an Excel worksheet function or a VBA built-in function. As far as I
know, the only exception is that you can't use a VBA function in a data
validation formula. You can, however, use a custom VBA function in a
conditional formatting formula.
I cover Sub procedures in the preceding chapter and Function
procedures in this chapter.

Chapter 9 has many useful and practical examples


of Function procedures. You can incorporate many
of these techniques into your work.

You might also like