View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Charles Williams Charles Williams is offline
external usenet poster
 
Posts: 968
Default UDF returns #NUM! with F9 or Application.CalculateFull if sheet no

Usually the best way is to assign the Range to a variant and then loop
through the resulting variant array, something like

dim vArr as variant
dim j as long
dim k as long
dim dblSum as double
vArr=SubSetRange.Value2
for j=lbound(varr,1) to ubound(varr,1)
for k=lbound(varr,2) to ubound(varr,2)
if isnumeric(varr(j,k)) then dblSum=dblSum+varr(j,k)
next k
next j

Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Greg" wrote in message
...
I did some debugging and I found out that the loop "For Each Cell in
Subset Range" is looping through the cells in the worksheet that is
active at the time the macro is run, instead of the worksheet of the
cell that contains the function. I need to find a way to loop through
the values on the sheet where the function is located instead of the
active sheet at the time when the subroutine is run regardless of
which sheet is active when the workbook is recalculated.

Does anyone know of a good tutorial on the best way to loop through
the values of a 2-D input range in a UDF?