A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can an array formula be used in a user defined function?



 
 
Thread Tools Display Modes
  #1  
Old July 5th, 2004, 04:43 PM
stratasmith
external usenet poster
 
Posts: n/a
Default Can an array formula be used in a user defined function?

Here's what I need to do:

I have a rectangular array with values for a number of variables
(columns) in a number of samples (rows).

In another (square) array, I want to generate the variance of the
natural log of the ratios of all possible pairs of variables. Thus,
cell mn of the output array has the variance of the logs of the ratios
of every pair of values in row m and row n of the input array. I can
do this for an individual cell of the output array with an array
formula, but as there are about 35 columns of variables there would be
over a thousand array formulas to type in!. I can't use Copy and
Paste, because of the way column n of the input becomes row n of the
output.

I could probably do it in a user defined function, but I'm not sure if
I can use an array formula in a udf, and someone may be able to think
up a more efficient way of doing what I want.

Any ideas?

SS.


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

  #2  
Old July 5th, 2004, 05:15 PM
Charles Williams
external usenet poster
 
Posts: n/a
Default Can an array formula be used in a user defined function?

You can use an excel array formula in a UDF if you use Application.Evaluate
or Worksheet.Evaluate to evaluate it.

It may well be faster to write a UDF that reads the rectangular range into
an array and then calculates the square output array and returns it when the
UDF is entered as an array formula.
The only problem would be that Excel limits you to returning a max of 5461
elements with an array formula UDF prior to Excel 2002 (well unless you want
to start making registry changes for Excel 2000).

Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com

"stratasmith " wrote in message
...
Here's what I need to do:

I have a rectangular array with values for a number of variables
(columns) in a number of samples (rows).

In another (square) array, I want to generate the variance of the
natural log of the ratios of all possible pairs of variables. Thus,
cell mn of the output array has the variance of the logs of the ratios
of every pair of values in row m and row n of the input array. I can
do this for an individual cell of the output array with an array
formula, but as there are about 35 columns of variables there would be
over a thousand array formulas to type in!. I can't use Copy and
Paste, because of the way column n of the input becomes row n of the
output.

I could probably do it in a user defined function, but I'm not sure if
I can use an array formula in a udf, and someone may be able to think
up a more efficient way of doing what I want.

Any ideas?

SS.


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



  #3  
Old July 5th, 2004, 06:29 PM
stratasmith
external usenet poster
 
Posts: n/a
Default Can an array formula be used in a user defined function?

I wasn't familiar with application.evaluate/worksheet.evaluate but I'll
look into them.

It's also occurred to me that I could do the whole thing with a
subroutine, looping through the cells of the output array (or at least,
those above the leading diagonal, as it's going to be mirrored in the
other half), but this might run up against the same limitation that you
mentioned. (I'm using Excel 97, by the way.)

Any other thoughts?

SS.


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

  #4  
Old July 5th, 2004, 07:45 PM
Charles Williams
external usenet poster
 
Posts: n/a
Default Can an array formula be used in a user defined function?

A Subroutine does not have the same 5461 limits as a worksheet function.

If you can use it as a sub attached to a button or something then I would
recommend using a sub.
VBA is surprisingly fast at handling arrays and arithmetic so this might be
the right approach.

Just make sure you read the input range in a single statement into a single
variant variable (not an array of variants) and process the results into a
square array of doubles:
something like this

Dim vArrIn as variant
dim j as long
dim k as long
dim dAnsa(100,100) as double
'
' setup excel environment
'
application.calculation=xlmanual
application.screenupdating=false
'
' get the input data
'
vArrIn =worksheets("sheet1").range("A1:IV10000")
'
' process input data
'
for j=1 to 10000
for k=1 to 256

...... =vArrIn(j,k)

dAnsa(jj,kk)= ...

next k
next j
'
' put results back to worksheet
'
worksheets("sheet2").range("z5").resize(100,100)=d Ansa
'
' restore excel environment
'
application.calculation=xlautomatic
application.screenupdating=true

Charles
______________________
Decision Models
The Excel Calculation Site.
www.DecisionModels.com

"stratasmith " wrote in message
...
I wasn't familiar with application.evaluate/worksheet.evaluate but I'll
look into them.

It's also occurred to me that I could do the whole thing with a
subroutine, looping through the cells of the output array (or at least,
those above the leading diagonal, as it's going to be mirrored in the
other half), but this might run up against the same limitation that you
mentioned. (I'm using Excel 97, by the way.)

Any other thoughts?

SS.


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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to access Joseph Meehan General Discussion 6 June 25th, 2004 08:37 AM
array formula to check if ranges are identical Harlan Grove Worksheet Functions 2 April 27th, 2004 05:58 AM
user defined function gaetanpelletier Worksheet Functions 1 February 20th, 2004 03:11 AM
array formula not working Scruff57 Worksheet Functions 7 January 15th, 2004 04:46 PM


All times are GMT +1. The time now is 01:44 PM.


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