Passing array arguments to VBA functions
Sorry if this is not posted in the right place, but there is no VBA forum...
I am working with VBA for Microsoft Excel. It is easy enough to pass an array to a function, but is there any way to pass a single column of a multi-dimensional array to a function? For example, if I have an array with 2 columns and 10 rows, can I pass just the second column to, say, the worksheetfunction.average() function?
If this is not possible, what is the best way to create a single-dimensional array copy of the desired column so that it may be passed to the function?
Thanks in advance!
[602 byte] By [
amotto] at [2007-11-11 10:31:53]

# 1 Re: Passing array arguments to VBA functions
Why not pass the entire array, plus a parameter indicating which column to average?
Function CalculateAverage(ByVal theArray() As Double, ByVal Column As Integer)
# 2 Re: Passing array arguments to VBA functions
I can do that, but then how do I run a worksheet function on only the desired column? For instance, worksheetfunction.average(myarray), will average all the elements in the array. I can manually loop through the array and calculate an average, but I would prefer to use the built-in excel functions. Thanks again.
amotto at 2007-11-11 17:23:38 >
