What are Procedures in Excel VBA

You will often hear the word Macro used when people talk about VBA procedures. But this really refers to Microsoft Excel prior to 1994.

An Excel procedure is defined as a group of statements (which you name) that are run as a unit. Each complete line of code is one statement.

You use VBA procedures to perform tasks such as controlling Excel’s environment, communicating with databases, analyzing data and much more. A VBA procedure unit or block consists of a procedure statement (Sub or Function) and an ending statement (End Sub) with your statements (lines of code) in between. A VBA procedure is constructed from three types of statements: executable, declaration and assignment. The statements between a procedure’s declaration and ending statement tell Excel what tasks you want it to do.

Excel Procedures are typed and stored in a Module. Procedures are executed or run (same meaning) in order to apply their statements. When a procedure is run, its statements are run from top to bottom line by line which in turn performs the operations. But, just typing a procedure in a module does not make it automatically run the code. Until you run it, it is nothing more than text sitting in a document. You run or execute a procedure by a variety of methods.

Excel VBA has two types of procedures. These are Sub Procedures and Function Procedures.

Sub Procedures
You write these when you want Excel to create a chart, analyse data, colour worksheet cells in, copy and paste data, insert rows and columns, insert worksheets, in fact too many to mention!

Function Procedures
You create these when you want to make your own custom worksheet functions or perform a particular calculation that will be used over and over again – saving you a lot of time. However, Sub Procedures can also do calculations.

If you want to do a task in Excel, then write a Sub Procedure. If you want to write a custom worksheet function, then write a Function Procedure. There is some overlap between the two types of procedures but do not let that bother you.

Leave a Reply

Your email address will not be published. Required fields are marked *