#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Arrays

Hi Everyone:

In excel, I am writing a function that returns an array, for example a
matrix. This function is called from the formula bar of the spreadsheet,
and returns the results to the spreadsheet. However, the array only fills
the cells that the user has selected prior to typing the name of the
function, its arguments and finally hitting Ctrl-Shift-Enter. I was
wondering if there is any way of forcing excel to output the complete array?
For example, if the user has selected 3x3 cells, but my output is 5x5, for
my function to show the result of all 5x5 elements?

Thanks for all your help.

Bob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 762
Default Arrays

Bob -

I was wondering if there is any way of forcing excel to output the
complete array? <


I don't think so. If it's a User Defined Function, it can only return values
to the worksheet cells where it resides. I think the only thing you can do
is encourage your users to select a very large range before array-entering
the function. As I recall, the extra cells will display the #N/A error code.

- Mike Middleton
http://www.DecisionToolworks.com
Decision Analysis Add-ins for Excel



"Bob" wrote in message
...
Hi Everyone:

In excel, I am writing a function that returns an array, for example a
matrix. This function is called from the formula bar of the spreadsheet,
and returns the results to the spreadsheet. However, the array only fills
the cells that the user has selected prior to typing the name of the
function, its arguments and finally hitting Ctrl-Shift-Enter. I was
wondering if there is any way of forcing excel to output the complete
array? For example, if the user has selected 3x3 cells, but my output is
5x5, for my function to show the result of all 5x5 elements?

Thanks for all your help.

Bob



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Arrays

Yes, it is quite simple.

First you count the rows (I am assuming it goes down) with

numRows = Application.Caller.Rows.Count

redim your temporary array to that size

Redim myArray (1 To numRows)

and then after your code loads the array, pad it like so

For i = current_last_value_index to NumRows

myArray(i) = ""
Next i

and load the array into the return value

myFunction = Aplication.Transpose(myArray)

If it has columns as well you will need to handle that in the Redim and with
an inner loop filling in the extra columns for each extra row.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bob" wrote in message
...
Hi Everyone:

In excel, I am writing a function that returns an array, for example a
matrix. This function is called from the formula bar of the spreadsheet,
and returns the results to the spreadsheet. However, the array only fills
the cells that the user has selected prior to typing the name of the
function, its arguments and finally hitting Ctrl-Shift-Enter. I was
wondering if there is any way of forcing excel to output the complete
array? For example, if the user has selected 3x3 cells, but my output is
5x5, for my function to show the result of all 5x5 elements?

Thanks for all your help.

Bob



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Arrays

Just so the OP's hopes aren't raised too much...

I think you missed the part where the user selected a 3x3 range and the OP still
wanted to return a 5x5 result.



Bob Phillips wrote:

Yes, it is quite simple.

First you count the rows (I am assuming it goes down) with

numRows = Application.Caller.Rows.Count

redim your temporary array to that size

Redim myArray (1 To numRows)

and then after your code loads the array, pad it like so

For i = current_last_value_index to NumRows

myArray(i) = ""
Next i

and load the array into the return value

myFunction = Aplication.Transpose(myArray)

If it has columns as well you will need to handle that in the Redim and with
an inner loop filling in the extra columns for each extra row.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bob" wrote in message
...
Hi Everyone:

In excel, I am writing a function that returns an array, for example a
matrix. This function is called from the formula bar of the spreadsheet,
and returns the results to the spreadsheet. However, the array only fills
the cells that the user has selected prior to typing the name of the
function, its arguments and finally hitting Ctrl-Shift-Enter. I was
wondering if there is any way of forcing excel to output the complete
array? For example, if the user has selected 3x3 cells, but my output is
5x5, for my function to show the result of all 5x5 elements?

Thanks for all your help.

Bob


--

Dave Peterson
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
Trouble with arrays (transferring values between two arrays) Keith R[_2_] Excel Programming 4 November 14th 07 12:00 AM
Anyone know anything about arrays and vba? If so, please help Need Help Fast![_2_] Excel Programming 6 March 21st 07 06:49 PM
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM
using arrays in vba JulieD Excel Programming 4 August 12th 04 04:59 PM


All times are GMT +1. The time now is 11:10 AM.

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

About Us

"It's about Microsoft Excel"