View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jean-Pierre Bidon Jean-Pierre Bidon is offline
external usenet poster
 
Posts: 30
Default Read directly a returned array in the calling routine

Quite simple indeed. Thank you.

"keepITcool" a écrit dans le message de news:
...

short and simple...

Function Array1()
Array1 = Array(1, 2, 3)
End Function

Function Array2()
Array2 = Array1
End Function

Function Array3() As String()
Dim v, r$(), i%
v = Array2
ReDim r(LBound(v) To UBound(v))
For i = LBound(v) To UBound(v)
r(i) = v(i)
Next
Array3 = r
End Function

since functions 1 and 2 have (implicit) variant datatype
you'll have to rework array3 to achieve a string array.

all 3 functions can be called by vba or from the worksheet.
this what you mean?

--
keepITcool
|
www.XLsupport.com | keepITcool chello nl | amsterdam


Jean-Pierre Bidon wrote :

Hi,
I posted a question 2 weeks ago to know if it was (is) possible to
retrun an array from a user defined function. I received a
satisfying answer, ... however it used a worksheet to get back the
array in a selected range. In looking again at this solution, it
call to mind another question: is the use of a worksheet unavoidable?
Or put differently, is it possible to get the returned array in a new
array declared in a calling routine, or to read the cells of the
returned array directly in this calling routine. Many thanks in
advance. Jean-Pierre