Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can an Excel Function return multiple values?

Status
Not open for further replies.

MigrantFirmWorker

Programmer
Apr 9, 2003
54
US
I am using a Function to calculate a variety of parameters from a set of data in a spreadsheet. I know I can pass a single value back to the calling cell through the return value. Is it possible to send additional values back to other cells? I tried passing cells in as arguments, but I have been unable to set their values from the function.

-chris
 
Functions in a worksheet can only return a value to ONE cell. They cannot affect any change on the worksheet other than to their own cell and they cannot affect any kind of formatting change Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Show us the code, as it currently is, and show us a modified copy. Of course, your modified copy won't work, you will have used psuedocode to indicate what you expect.

 
Chris, it sounds like an example of the sort of function you are looking for might be to convert cartesian coordinates to polar coordinates. You could use two separate functions like this:
Code:
A1: 'X-coord
B1: 'Y-coord
C1: 'Theta
D1: 'r
A2: 312
B2: 521
C2: =PolarAngle(A1,B1)
D2: =PolarDistance(A1,B1)
Or you could use just one function with a third parameter to indicate which value to return like this:
Code:
C2: =PolarCoord(A1,B1,1)
D2: =PolarCoord(A1,B1,2)
If you have a very time-intensive calculation that takes many input values and generates many output values and are concerned about performance, then the parameterized version of a single function is the way to go.

The thing to do is save the input and output values in global variables and test whether the solution has already been found for the current set of input values. If so, just select the appropriate output value and return it. If not, do a full calculation and capture the values for the next call. Then return the wanted value.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top