What is a VBA Procedure, Sub Procedure, Function Procedure?

Call us at:   1.805.498.7162     1.805.558.9277--

Learn about how we can help your company or yourself achieve your Microsoft Excel training or self-study goals Visit our free Microsoft Excel and Microsoft Excel VBA resource center Learn how we can help save your company money with our innovative software solutions Visit out VBA code center for code that can save your company money Learn about our Excel Add-In software that can save your company time and money View our customer list from our 12 years in business Phone numbers, request form and email address Learn about EMAGENIT View our training schedule for Microsoft Excel and Microsoft Excel VBA

What is a VBA Procedure?

  • The word Macro is slang for the word VBA procedure. It is a throw back to pre 1994 Microsoft Excel.

  • A procedure is defined as a named group of statements that are run as a unit. A statement is simply 1 complete line of code.

  • VBA procedures are used to perform tasks such as controlling Excel’s environment, communicating with databases, calculating equations, analyzing data…etc

  • A VBA procedure unit or block consists of a procedure statement (Sub or Function) and an ending statement with statements in between.

  • A VBA procedure are constructed from three types of statements: executable, declaration and assignment statements. The statements between a procedure’s declaration and ending statement (i.e. Sub and End Sub) perform the procedure's task; what you are trying do.

    • For example, the procedure to the right commands Excel's Sort feature on the active worksheet when it is run.

  • 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 (i.e. lines) are executed in a top-down line by line fashion performing operations. Think of reading a book page. Note that typing a procedure in a module does not run it. You must do this after typing it by variety of different methods. Until you run it, it is just basically text sitting in a document.

  • VBA has two types of procedures: Sub procedures and Function procedures.

Sub Procedures

  • Sub procedures are written when you want to command Excel like creating a chart, analyzing data, coloring cells, copying and pasting data...etc.

Function Procedures

  • Function procedures are created when you want to make your own custom worksheet functions or perform a calculation that will be used over and over again. Note that Sub procedures can also do calculations.

What to Write

  • So if you want to do a task in Excel, you write a Sub procedure, if you want to write a custom worksheet function, you write a Function procedure. Are their grey areas between the two, yes, but do not worry about them when first starting out.

    .

Back to the Resource Center

VBA Sub Procedure Example

VBA Function Procedure Example

 
How We Can Help With Your Training?

Self-Study Training

Public Workshops

On-Site Training

Webcast Training

Our self-study manuals contain extensive Microsoft Excel and Microsoft Excel VBA knowledge based on our consulting and software design experiences. They contain not only how-to information, but also practical application discussions. In our manuals, you get everything we use when we develop for clients. EMAGENIT has developed software for such company's as Northrop Grumman, NASA JPL, Caterpillar and the US Navy. View Manuals and Prices...  

In our Microsoft Excel and Microsoft Excel VBA public workshops, you will learn "hands-on" from an experienced Excel developer. Our Microsoft Excel developers have real world experience designing worksheets and software for companies and organizations like Verizon, Caterpillar, The US Navy and NASA JPL. We limit our public workshops to 10 people or less so we can concentrate on your problems. Our workshops are never "canned" and we adjust the curriculum of each class based on the particular needs of the attendees. Best of all, you can repeat the workshop as many times as you want free. Schedule and Workshop Information...

Our onsite workshops feature “hands-on” training custom designed to your company’s needs. EMAGENIT provides this customization of Excel or Excel VBA curriculum at no extra cost. EMAGENIT has an extensive training and development background that is integrated into every class. With over 14 years of experience and knowledge, we can help solve your Excel problems. Our onsite training is also less expensive than your staff taking our public workshops. More Information... Using our live webcast technology, EMAGENIT can train you or your company from anyplace in the world. We can simulcast our public workshops or train your company exclusively through our live webcast. EMAGENIT's webcast is fast becoming a valuable tool for many company's as they try to keep costs down and productivity up. Our webcast gives you a live, voice interactive and "hands-on" workshop tailored to your needs.  Schedule and Workshop Information...