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.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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.
 
Upvote 0
Can you provide an example of how that would appear in code - both as an argument and defined in the function?

Many thanks.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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
Back
Top