Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Passing an array in a user defined function

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






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Passing an array in a user defined function

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






  #3   Report Post  
Posted to microsoft.public.excel.programming
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array in a user defined function Peter M Excel Programming 5 June 27th 08 10:45 PM
Passing Array of User Defined Type to Form dunnerca Excel Programming 4 December 23rd 07 09:22 PM
Passing a range to a user defined function Gary Nelson Excel Discussion (Misc queries) 1 July 19th 07 04:22 PM
Passing User Defined Type Array to Listbox PC[_4_] Excel Programming 2 June 1st 05 02:44 AM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 03:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"