View Single Post
  #13   Report Post  
david cassain
 
Posts: n/a
Default

On 26 May 2005 14:49:00 -0700, "Harlan Grove" wrote:

david cassain wrote...
...
Sadly, the code in the MyFunct function is 300+ lines of handicapping
business rules that are unit tested and work flawlessly, and return a
single value for any vba array passed in. {big sigh} So I wouldn't
make anyone parse through it, but thanks.

...

OK, generalities.

If the ranges you'd pass to this udf were always effectively 1D, then
you could put the following near the top of your function's code. I'll
use 'a' to denote the argument that should be processed as an array.


Dim t() As Double, n As Long, x As Variant

If TypeOf a Is Range Then
ReDim t(1 To a.Cells.Count)
For Each x In a
n = n + 1
t(n) = CDbl(x.Value)
Next x
a = t 'makes a contain the values as a 1D array
Erase t
ElseIf Not IsArray(a) Then
ReDim t(1 To 1)
t(1) = a
a = t
Erase t
End If
'at this point the variable a contains and array no matter if it
started
'off containing a range reference or a scalar


Wow! thanks so much! When I asked the original question I assumed it
was merely a syntax issue that needed correction. But you've solved
the problem AND provided some branching code as workaround.

It still strikes me as a bit weird that I can pass a literal array
{1,2,3,..,n} from a worksheet function successfully, but there is no
equivilent way to pass a range reference that would work. I still
have to wrap my head aroud that...

anyways, thanks again Harlan. You probably saved me from 2 days of
trial and error agony.

dave