View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Laurie Laurie is offline
external usenet poster
 
Posts: 37
Default Passing an array in a user defined function

Thanks Joel!!

I am gonna try your suggestion.

One more thing is that in specifying "Array1 as Variant" as a parameter for
the UDF "name1" or "name2", will "Array1() as Variant" also be ok?

Thanks again,
Laurie



"Joel" wrote:

Function name1(Array1 As Variant)

Array_Sum = 0
For i = 1 To UBound(Array1)
Array_Sum = Array_Sum + Array1(i)
Next i
name1 = name2(Array1, "a", "b", "C")

End Function


Function name2(Array1 As Variant, parm2, parm3, parm4)

Array_Sum = 0
For i = 1 To UBound(Array1)
Array_Sum = Array_Sum + Array1(i)
Next i

name2 = Array_Sum
End Function


"Laurie" wrote:

Hi,

I am wondering that, in the below post from Charles (on Feb 3rd, 2005),
after declaring "Array1 as Variant" in the user-defined function name, then
in the UDF codes, should we declare Array1 again for its dimension(s)?

Basically, how to make use of Array1 in the UDF, if Array1 has been defined
in another UDF?

For example,

1. In defining the UDF function 1:

Functionname1()

--- Array1 is defined and assigned values
--- Functioname2(Array1,...)

End Function

2. In defining the UDF function 2:

Funcitonname2(Array1 as variant, ...)
...
End Function


My questions a

a) In item 1 above for defining the functionname1 to use the second UDF
functionname2, what is the right syntax for specifying Array1 as a parameter
arguement of functionname2?

b) In item 2 above for defining the functionname2, how do we use the Array1
or how do we change the elements' values of Array 1 in the functionname2?

Thank you very much in advance and any suggestion would be highly
appreciated!!!


Sincerely,
Laurie



"Charles Williams" wrote:

On the Worksheet =FunctionName({1,2,3,4,5},constant)

in the VBA function you then have to assign to a Variant

Function FunctionName(Array1 as variant, Constant as ...) as ...


Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

"Peter M" wrote in message
...


How do I pass an array in a user defined function? E.g.,

=FunctionName(Array1, Constant, ...)


--
Thanks for any help