CREATING CUSTOM FUNCTIONS

In case you cannot find a function that suit your needs, VBA provide you with the ability to create your own custom functions for Excel.

In the same way that a macro lets you encapsulate a sequence of actions execute that sequence with a single command, a custom function lets you encapsulate a sequence of calculations so that you can perform those calculations with a single formula.

Custom functions, like macros, use the Visual Basic for Applications (VBA) programming language.

They differ from macros in two significant ways. First, they use function procedures instead of sub procedures. They start with a Function statement instead of a Sub statement and end with End Function instead of End Sub.

Second, they perform calculations and return a value instead of taking actions.

Certain kinds of statements (such as statements that select and format ranges) are excluded from custom functions.

In this chapter, you learn how to create and use custom functions.

  1. Creating Custom Functions
  2. Using Custom Functions
  3. Understanding Custom Function Rules
  4. Using VBA Keywords in Custom Functions
  5. Documenting Macro and Custom Functions
  6. Creating Custom Functions with Optional Arguments
  7. Making Your Custom Functions Available Anywhere