


For example, you could have a VBA Sub procedure that adds an Integer to every cell in the current selected range on a worksheet. VBA procedures can be passed data via arguments, which are declared in the procedure definition. formatting a set of cells), you might choose to use a Sub procedure. summing of a group of numbers), you will generally use a Function procedure, but if you just need a set of actions to be carried out (e.g. Therefore, if you wish to perform a task that returns a result (e.g. The main difference between a VBA Function procedure and a Sub procedure is that a Function procedure returns a result, whereas a Sub procedure does not.

In Excel Visual Basic, a set of commands to perform a specific task is placed into a procedure, which can be a Function procedure or a Sub procedure (also known as functions and subroutines). User-Defined VBA Function & Sub Procedures Before you consider creating your own VBA Functions, it is useful to know that there are a large number of built-in VBA functions that you can use in your code.įor a list of the main built-in VBA functions, with examples, see the VBA Functions page.
