Sorry for the ambiguous statment. I certainly didn't mean to imply that a 1D
array could be ReDimmed into a 2D array. I meant that the OP could initially
ReDim dTmp into a 2D array, fill it as desired, and return it through the
function name. Much like your example further down.
"Jim Thomlinson" wrote:
> You can not redim a 1d array into a 2d array. Additionally if you redim a 2 d
> array you can only redimension the first element.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Charlie" wrote:
>
> > Correction
> >
> > Dim dTmp() as Double
> >
> >
> > BTW, you can also ReDim dTmp as a two-dimension array and your array
> > function will return a 2D array!
> >
> >
> >
> > "Charlie" wrote:
> >
> > > To declare a function as an array function it must be typed as String, Long,
> > > Double, etc., not Variant
> > >
> > > Public Function XYCoords(X as String, Y as String) As Double()
> > >
> > > Dim dTmp as Double
> > >
> > > ReDim dTmp(2) 'Note - I always use Option Base 1 in all my modules
> > >
> > > dTmp(1) = CDbl(X)
> > > dTmp(2) = CDbl(Y)
> > > XYCoords = dTmp
> > >
> > > End Function
> > >
> > > End Function
> > >
> > > "ExcelMonkey" wrote:
> > >
> > > > I want to create a function which returns an array. For Example I want
> > > > ArrayFunction to return X,Y.
> > > >
> > > > I will then load the results of the Function into a 2D Array with 2 colums:
> > > >
> > > > Private FunctionArray(A as String, B as String) As Variant
> > > > 'This needs to produce a result that looks like X,Y
> > > >
> > > > End Function
> > > >
> > > > How do I set up the function to return an array result (2 values)?
> > > >
> > > >
> > > > Thanks
> > > >
> > > > EM
|