Breaking Code Down into Procedures

A procedure is a unit of code enclosed either between the Sub and End Sub statements or between the Function and End Function statements. A procedure should accomplish a simple, well-defined task. Procedures are often used for performing repeated or shared tasks.

If your code contains a procedure that performs a complicated task, break that procedure down into several smaller procedures, and then write a separate procedure to call these procedures in order. Continue to examine and break down each procedure in your code until each procedure is simple and specific. The simpler the task performed by a procedure, the easier it will be for you to write and debug it. The more specific the task performed by a procedure, the more versatile the procedure will be.