Share via


Using Parameter Arrays

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