ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pass a Variable List Of Values To Subroutine or Function (https://www.excelbanter.com/excel-programming/321884-pass-variable-list-values-subroutine-function.html)

Dean Hinson[_3_]

Pass a Variable List Of Values To Subroutine or Function
 
Hello All,

What I want to do is create a function (maybe subroutine) that will be
passed a variable number of values and perform some processing. I am not
sure this is possible because the functions I have created in the past has a
finite number of parameters.

Has anyone done this?

Thanks in advance.

Dean.

JE McGimpsey

Pass a Variable List Of Values To Subroutine or Function
 
I do this frequently. Look at "Understanding Parameter Arrays" in VBA
Help



In article ,
"Dean Hinson" wrote:

What I want to do is create a function (maybe subroutine) that will be
passed a variable number of values and perform some processing. I am not
sure this is possible because the functions I have created in the past has a
finite number of parameters.

Has anyone done this?


Bob Phillips[_6_]

Pass a Variable List Of Values To Subroutine or Function
 
Take a look at ParamArray in VBA help, just what you need. Here is a simple
example

Public Function weightedstdev(ParamArray rng())
Dim rngCount
rngCount = UBound(rng, 1)
For i = 0 To rngCount
' your code
Next
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dean Hinson" wrote in message
...
Hello All,

What I want to do is create a function (maybe subroutine) that will be
passed a variable number of values and perform some processing. I am not
sure this is possible because the functions I have created in the past has

a
finite number of parameters.

Has anyone done this?

Thanks in advance.

Dean.





All times are GMT +1. The time now is 04:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com