Using Parameter Arrays

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You can pass an array of arguments to a procedure by using a parameter array. The advantage to using a parameter array is you are not required to know at design time how many arguments will be passed to a procedure — you can pass a variable number of arguments when you call it.

To define a parameter array, use the ParamArray keyword followed by an array of type Variant, as shown in the following procedure definition:

Function SomeProc(ParamArray avarItems() As Variant)

A parameter array always must be an array of type Variant, and it always must be the last argument in the argument list.

To call a procedure that includes a parameter array, pass in a set of any number of arguments, as shown here:

? SomeProc("red", "yellow", "blue", "green", "orange")

Within the body of the procedure, you can work with the parameter array as you would with any other array.

See Also

Tips for Defining Procedures in VBA | Using Optional Arguments | Passing Arguments by Value or by Reference