View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Returning range object from custom functions

Public Function MyFunc(rng as Range, i as Long) as Range
set MyFunc = rng.offset(0,i)
End Function

--
Regards,
Tom Ogilvy

"agarwaldvk " wrote in message
...
Can anyone tell me how to return range objects from custom functions?

The idea is this :=

If we were to use the built-in Excel function sum like "=sum(e4)", it
will return the value contained in the cell e4. No problem there!
However, if we were to use a function like "sum(address(5,4)), it
returns an error.

My interpretation to this is that the built-in Excel function
"address()" returns the address as a string and not a range object and
the built-in Excel function sum() requires a range object to be passed
as an argument to it. To overcome this limitation, my intention is to
be able to write a custom function whereby I can return a range object.
If I were to be able to do that, then the above problem could be
addressed like so :=

"=sum(myFunc(single cell range passed as argument for simplicity))" -
presume that my custom function myFunc returns the range object!

This function may seem useless at the moment but this is just the
starting point to what I eventually want to do, which I can explain if
someone really want to know but as such is not required to provide a
solution to my query.

Best regards


Deepak Agarwal


---
Message posted from http://www.ExcelForum.com/