座右铭: 只做有益人类的事 不做有害人类的事
|
|
Use array in a costomized worksheet function
Zhanshan Dong
We know there are a lot of worksheet functions that use an array as an argument. How can we use an array as an argument in our costomized worksheet functions? I'd like to address this question step by step.
1) The function declaration. In the function declaration part, you should declare an array parameter as an object. For example,
Function Test(Range1 as Object)
2) To access the elements in an input array. You can use traditional For-Next loop to access the elements in an array as we do for arrays declared in the function by DIM command.
3) To get the dimension size of an input array. Use UBOUND function to achieve the purpose. For example,
nSize = UBound(Range1(), 1)
This command will get the size of the first dimension of the input array. It is worthy to mention that the input array in the UBound function must be written like array name followed a pair of parentheses.
To see an example of using an input array, please refer to an article called "Enhanced Chi-Square Test Function in Excel".
|
|