Variable number of arguments in ParamArray ArgList()

Excel VBA guy picture Excel VBA guy · Jun 4, 2009 · Viewed 12.8k times · Source

If I want to pass a number of values for the ParamArray arglist via an array, how do I do it? From what I've read so far, on VBA, it appears that I need to explicitly list the values that I want to pass. But what if there are potentially different numbers of values to pass, so I do not know in advance how many I'll want to pass to the function? Is there not some way of using an array (a one-dimensional array) with a variable dimension?

Answer

barrowc picture barrowc · Jun 5, 2009

There are several ways to achieve that:

  • dimension the array to be larger than you require, keep a count of how many items actually get added and then Redim Preserve back to the correct size
  • use a Collection object instead (as a normal parameter rather than a ParamArray)