Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to use function that returns array of variable size?

I have a VBA function that returns an array of variable size.
How do I use it in the spreadsheet without knowing the size
(and perhaps not even the shape) a priori?

Consider the following trivial example:

function mytest()
dim myarr(3,1)
myarr(0,0) = 1: myarr(1,0) = 2: myarr(2,0) = 3
mytest = myarr
end function

Normally, I use it by highlighting 3 cells in a column, enter
=mytest(), then press ctrl-shift-Enter.

But what if I did not know the function returned 3 elements,
but (a) I knew the shape, or (b) I did not even know the
shape?

Ideally, I would like to highlight just the upper-left corner
(like cut-and-paste of multiple cells), enter =mytest(), and
press ctrl-shift-Enter. Of course, that does not have the
desired effect (namely, filling in adjacent with cells with the
entire array result).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default How to use function that returns array of variable size?

A user defined function can only effect the cell that it is in when called
from a sheet. There is no way around that. If called from ithin code it can
effect whatever cells it want to, but not when called froma cell.
--
HTH...

Jim Thomlinson


" wrote:

I have a VBA function that returns an array of variable size.
How do I use it in the spreadsheet without knowing the size
(and perhaps not even the shape) a priori?

Consider the following trivial example:

function mytest()
dim myarr(3,1)
myarr(0,0) = 1: myarr(1,0) = 2: myarr(2,0) = 3
mytest = myarr
end function

Normally, I use it by highlighting 3 cells in a column, enter
=mytest(), then press ctrl-shift-Enter.

But what if I did not know the function returned 3 elements,
but (a) I knew the shape, or (b) I did not even know the
shape?

Ideally, I would like to highlight just the upper-left corner
(like cut-and-paste of multiple cells), enter =mytest(), and
press ctrl-shift-Enter. Of course, that does not have the
desired effect (namely, filling in adjacent with cells with the
entire array result).

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default How to use function that returns array of variable size?

On Mon, 13 Feb 2006 08:45:14 -0800, "
wrote:

I have a VBA function that returns an array of variable size.
How do I use it in the spreadsheet without knowing the size
(and perhaps not even the shape) a priori?

Consider the following trivial example:

function mytest()
dim myarr(3,1)
myarr(0,0) = 1: myarr(1,0) = 2: myarr(2,0) = 3
mytest = myarr
end function

Normally, I use it by highlighting 3 cells in a column, enter
=mytest(), then press ctrl-shift-Enter.

But what if I did not know the function returned 3 elements,
but (a) I knew the shape, or (b) I did not even know the
shape?

Ideally, I would like to highlight just the upper-left corner
(like cut-and-paste of multiple cells), enter =mytest(), and
press ctrl-shift-Enter. Of course, that does not have the
desired effect (namely, filling in adjacent with cells with the
entire array result).


1. AFAIK, you can't just highlight the upper-left corner with a UDF any more
than you could with a built-in worksheet function that returns an array.

2. You could highlight an area larger than the conceivable return, and "white
out" the error messages with conditional formatting.

3. You could use the INDEX function in a similar manner, and use an IF
function to get rid of the error messages.

e.g. =IF(ISERR(INDEX(MYTEST(),3,3)),"",INDEX(MYTEST(),3 ,3))



--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to use function that returns array of variable size?

"Jim Thomlinson" wrote:
A user defined function can only effect the cell that it
is in when called from a sheet.


Right. Just testing to see if you're awake ;-). Kidding!
My bad. I realized after posting that I really wanted a
macro (sub). ActiveCell.Offset suits my purposes.
Thanks for the quick response.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array function that returns values within several intervals Hjuler Excel Worksheet Functions 6 September 23rd 08 04:11 PM
Using Array variable in FIND function JMB Excel Programming 1 November 1st 05 03:59 PM
Using Array variable in FIND function JMB Excel Programming 0 October 31st 05 11:55 PM
Define an array with variable size Yiu Choi Fan Excel Programming 3 July 9th 04 11:29 AM
How to find out the size of a variable-size array ? Adrian[_7_] Excel Programming 1 July 6th 04 09:12 AM


All times are GMT +1. The time now is 07:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"