O'Reilly logo

Excel VBA Programming For Dummies, 3rd Edition by John Walkenbach

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5

VBA Sub and Function Procedures

In This Chapter

arrow Understanding the difference between Sub procedures and Function procedures

arrow Executing Sub procedures (many ways)

arrow Executing Function procedures (two ways)

Several times in preceding chapters, I mention Sub procedures and allude to the fact that Function procedures also play a role in VBA. In this chapter, the secrets are revealed, and I clear up any confusion about these concepts.

Subs versus Functions

The VBA code that you write in the Visual Basic Editor is known as a procedure. The two most common types of procedures are Sub and Function.

check.png A Sub procedure is a group of VBA statements that performs an action (or actions) with Excel.

check.png A Function procedure is a group of VBA statements that performs a calculation and returns a single value (or an array).

Most of the macros you write in VBA are Sub procedures. You can think of a Sub procedure as being like a command: Execute the Sub procedure and something happens. (Of course, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required