View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default extracting a subset of an array with VBA.

"Alan Beban" wrote...
You might want to consider the SubArray function in the freely
downloadable file at http://home.pacbell.net/beban.

....
y wrote:
I need to extract an array from another. The dest array will
contain,e.g., the even elements of the first one.


There are two ways to read the OP's request: the resulting array contains
the even index entries or the even valued entries of the original
range/array. Having reread the code for SubArray, it's not immediately
obvious to me how it could accomplish either of these tasks. Perhaps you
could respond and enlighten with some actual code showing how SubArray could
be used to do either of these tasks.

To the OP: if you want a VBA function to return an array, the function's
return type must be Variant and you'd assign an array to its result. As a
simplistic example,

Function foo(n As Long) As Variant
Dim i As Long, rv As Variant
ReDim rv(1 To n)
For i = 1 To n
rv(i) = i
Next i
foo = rv
End Function