Sum part of range passed to UDF
You might be able to reconstruct your ranges so you can use the
WorksheetFunction.Sum function, but I doubt if that would be faster than
your simple loop. I still think your slow down is the UDF itself. If you can
reduce the calculation for the weeks of demand to a worksheet formula and
put that formula in my sample suggested location of S2, you could use the
formula I posted for the summation and not use any UDF (which are much
slower than worksheet formulas). The only thing that might have to be
addressed with the summation formula is absolute versus relative address
depending on whether your formulas would be copied down or across.
Rick
wrote in message
...
The other parameters I mentioned are for a separate calculation to
determine how many weeks of demand to calculate.
This code is a simplified version of what I have:
Public Function StockTarget(WeeksTotalDemand As Integer, rngDemand
As Range)
Dim ThisWeek As Integer
For ThisWeek = 1 To WeeksTotalDemand
StockTarget = StockTarget + rngDemand(ThisWeek)
Next ThisWeek
End Function
Is there a way to replace the for-next loop with a single sum
function?
|