Exiting Functions and Subroutines

The previous section described the Return statement, which provides one way to exit a function. The Exit Function statement provides another. The second and third statements shown here are equivalent to the first one:

Return strOut

Proper = strOut ' (Assuming Proper is the function's name.)
Exit Function

As you might suspect, there’s also an Exit Sub statement that immediately exits a subroutine. Both kinds of Exit statements are useful for avoiding long If statements and therefore simplifying your code, but don’t go crazy with them. A function or subroutine with dozens of exit points is hardly simple.

The most common—and often the best—way of exiting a function is simply to reach the End Function statement. Likewise, ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.