excel - Custom User Function (UDF) and Dynamic Ranges -


i have custom user function (udf) returns array. use in array formula on large range of cells.
length of returned array dependent on function parameters. works great except 1 thing: when length of returned array smaller range defined array-formula, "out-of-range" entries set #n/a.

is there way either obtain array-formula range inside custom user function (so, if needed, prepare larger array return), or alternatively return kind of iterator (instead of array) not limited in size , return "" in case of out-of-range?

here pretty dumb example......a udf return first 7 primes in column form:

public function primes() ' '   array udf return first 7 primes '     dim rn long, ary(1 7) long     dim tdim long, long     dim wf worksheetfunction     set wf = application.worksheetfunction      rn = application.caller.rows.count     tdim = wf.max(rn, 7)     redim bry(1 tdim, 1 1)      ary(1) = 1     ary(2) = 3     ary(3) = 5     ary(4) = 7     ary(5) = 11     ary(6) = 13     ary(7) = 17      = 1 7         bry(i, 1) = ary(i)     next      if tdim > 7         = 8 tdim             bry(i, 1) = ""         next     end if     primes = bry end function 

the udf detects how many cells has fill , if value exceeds 7, balance filled blanks.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -