Unlimited Arguments for Custom Functions

andreacosta

New Member
Joined
Sep 23, 2009
Messages
2
I just started fooling around w/ VBA yeseterday, so I'm still getting my bearings.
I know how to create functions in which the arguments are explicitly stated i.e.
Code:
Function LINK3(num1, num2, num3)
     num1 = (1 + (num1 / 100))
     num2 = (1 + (num2 / 100))
     num3 = (1 + (num3 / 100))
LINK3 = (WorksheetFunction.Product(num1, num2, num3) - 1) * 100
 
End Function
But how would I modify the function to include any number of arguments? i.e.
Code:
Function LINK3(num1, num2, num3)
     num1 = (1 + (num1 / 100))
     num2 = (1 + (num2 / 100))
     num3 = (1 + (num3 / 100))
     ...
     numx = (1 + (numx/100))
LINK3 = (WorksheetFunction.Product(num1, num2, num3..., numx) - 1) * 100
 
End Function
I've seen ParamArray being applied in certain instances where the number of arguments can vary....not sure if that can be used in this case.
Any assistance is much appreciated.
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

swat2

Board Regular
Joined
Jul 23, 2009
Messages
173
You might consider passing a Range object to the function. each range element doesn't have to be defined and can be parsed in the function itself.
 

andreacosta

New Member
Joined
Sep 23, 2009
Messages
2
Can you provide an example of how that would appear in code - both as an argument and defined in the function?

Many thanks.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,436
Messages
5,596,106
Members
414,042
Latest member
Swiftkoala

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top