View Single Post
  #12   Report Post  
Harlan Grove
 
Posts: n/a
Default

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