To get the output using a formula (which is implied by your example), you would have to use a formula over an array range. ie. A range that shares the same single formula. This is because a UDF called by a range cannot manipulate the Excel environment; it can only return a result. So your array range would have to be the size of the maximum number of results in any scenario. It would be easier to call the function via another means so that it can simply write the results without this restriction.