ParamArray

The ParamArray keyword allows you to accept a dynamic number of arguments.
The word ParamArray is an abbreviation for parameter array.
Instead of using a large number of optional parameters it might be better to use a parameter array instead.
This can only be used as the last argument in a procedure or function.
This keyword cannot be used with ByRef, ByVal or Optional (it is always ByRef).
The parameter array must be defined with a Variant data type.
The parameter array is always zero based and is not effected by the Option Base statement.
The parameter array can contain different data types, including objects.


Accessing with a For Each - Next Loop

This subroutine requires one integer argument.
Followed by any number of other arguments.
These arbitrary arguments can be of any data type.
This subroutine uses a For-Each-Next loop to through the parameter array.


Accessing with a For - Next Loop

This subroutine uses a For-Next loop to loop through the parameter array.


Empty Parameter Array

This subroutine can detect if the parameter array is empty.
Instead of leaving the argument completely blank you could pass in the keyword Nothing.


Passing In One Dimensional Array

These two subroutines will extract the arguments when they are passed in using a one dimensional array.
This subroutine extracts the one dimensional array from the first argument and then uses a for-loop.

It is possible to access the arguments directly using an 'array of array' type syntax.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext