View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] cwrm4@yahoo.com is offline
external usenet poster
 
Posts: 12
Default Sum part of range passed to UDF

I am passing a range, along with some other parameters, to a UDF that
calculates a safety stock requirement.

Based on the other parameters I send to the UDF, the UDF needs to
return the sum of a certain number of sequential elements in the
range. For example, if the range contains (2, 2, 2, 3, 3, 3, 4, 4, 4),
and I need 4 weeks of safety stock, the UDF should sum 2 + 2 + 2 + 3.

Would there be a way to sum with a single command the first four
values the above range? Currently I am looping through the range and
adding the "next" value on each loop through the range. However, I am
hitting some performance issues (this UDF is several hundred times in
the workbook) and am looking for a faster method.