Variable number of arguments

M

mcescher

Hi All,
I'm sure this has been addressed before, but I couldn't come up with
the correct search terms to find it.

It seems that I heard one time that there is a way to define a
function with a variable number of arguments. Is this possible? What
is the construct?

Thanks for your time,
Chris M.
 
M

Marshall Barton

mcescher said:
I'm sure this has been addressed before, but I couldn't come up with
the correct search terms to find it.

It seems that I heard one time that there is a way to define a
function with a variable number of arguments. Is this possible? What
is the construct?


Decalare your procedure's last argument with the ParamArray
keyword. See Function Statement in VBA Help

E.g.

Public Function MySum(ParamArray varList())
For Each X in varList
MySum = MySum + x
Next x
End Function
 
M

Marshall Barton

mcescher said:
I'm sure this has been addressed before, but I couldn't come up with
the correct search terms to find it.

It seems that I heard one time that there is a way to define a
function with a variable number of arguments. Is this possible? What
is the construct?


Decalare your procedure's last argument with the ParamArray
keyword. See Function Statement in VBA Help

E.g.

Public Function MySum(ParamArray varList())
For Each X in varList
MySum = MySum + x
Next x
End Function
 
M

mcescher

Decalare your procedure's last argument with the ParamArray
keyword.  See Function Statement in VBA Help

E.g.

Public Function MySum(ParamArray varList())
        For Each X in varList
                MySum = MySum + x
        Next x
End Function

Thanks to all who replied. That was just what I was looking for.

Chris M.
 
M

mcescher

Decalare your procedure's last argument with the ParamArray
keyword.  See Function Statement in VBA Help

E.g.

Public Function MySum(ParamArray varList())
        For Each X in varList
                MySum = MySum + x
        Next x
End Function

Thanks to all who replied. That was just what I was looking for.

Chris M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top