Excel VBA Procedures


This entry is part 1 of 1 in the series Excel VBA Procedures
  • Excel VBA Procedures

A procedure is a series of VBA statements that resides in a VBA module. A module can hold any number of procedures. Modules are accessed in the Visual Basic Editor (VBE). You can open the VBE with Alt+F11. In this post there are a few suggestions when you are creating your procedures in VBA. VBA is an extensive topic that I only briefly touch on in this post.

Best practice is to make your procedures only do one thing and not have them too long. You can create a main procedure that calls these other procedures you wrote. This will make your code easier to maintain. Also, your comments should describe what the procedure is supposed to do instead of describing what each line of code is doing. Each line of code will document itself.

Some procedures are written to receive arguments. An argument is information that is used by the procedure and that is passed to the procedure when it is executed.

There are three types of procedures: Sub, Function and Property. Function procedures can return a value after they finish executing. Sub procedures cannot return a value. Function procedures are a special pair of procedures with the same name that can implement an object property. That’s for another discussion at a later time.

VBA Environment

You can open the VBA environment from Excel in two ways: Alt+F11 and By going to the Microsoft Excel Developer tab and then clicking the Visual Basic button.

If the Excel Developer tab is not visible you can follow these steps to make it visible.

  1. Click the Excel File tab and select Options to show the Excel Options dialog box.
  2. Select the Customize Ribbon option.
  3. In the right list box, check the Developer tab.
  4. Click OK to close the Excel Options dialog box.