Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Functions that return multiple calculated values

I'm trying to write a function that will return multiple calculated
values. One way is to use the Array() function, which creates a
variant array, such as:

Function test()
Dim y As Variant
y = Array("a", "b")
test = y
End Function

However, I want to be able to output two CALCULATED values for y(1)
and y(2). If I try to do this in the code above, e.g. if ... then
y(1)=26, I get an error.

Am I missing somthing obvious?

Thanks in advance for any good ideas.

Tom Kreutz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Functions that return multiple calculated values

Tom,

This works okay for me

Function test()
Dim y As Variant
ReDim y(1)
If Day(Date) 20 Then
y(1) = 1
Else
y(1) = 0
End If
test = y
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tom Kreutz" wrote in message
m...
I'm trying to write a function that will return multiple calculated
values. One way is to use the Array() function, which creates a
variant array, such as:

Function test()
Dim y As Variant
y = Array("a", "b")
test = y
End Function

However, I want to be able to output two CALCULATED values for y(1)
and y(2). If I try to do this in the code above, e.g. if ... then
y(1)=26, I get an error.

Am I missing somthing obvious?

Thanks in advance for any good ideas.

Tom Kreutz



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Functions that return multiple calculated values

Bob,

Thanks for your note. I want the function to return TWO calculated
results. John Walkenbach's book "Excel 2000 Power Programming with
VBA" says that that can be done by returning a variant array (as
opposed to an array of variants). Your note got me to trying the
simpler idea of just returning a standard array, which works fine!!
For example:

Function test()
Dim y(2) As Integer
y(0) = 6
y(1) = 7
test = y
End Function

This returns the values 6 and 7 in two different cells, as I wished.

Thanks for your help.

Tom

"Bob Phillips" wrote in message ...
Tom,

This works okay for me

Function test()
Dim y As Variant
ReDim y(1)
If Day(Date) 20 Then
y(1) = 1
Else
y(1) = 0
End If
test = y
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tom Kreutz" wrote in message
m...
I'm trying to write a function that will return multiple calculated
values. One way is to use the Array() function, which creates a
variant array, such as:

Function test()
Dim y As Variant
y = Array("a", "b")
test = y
End Function

However, I want to be able to output two CALCULATED values for y(1)
and y(2). If I try to do this in the code above, e.g. if ... then
y(1)=26, I get an error.

Am I missing somthing obvious?

Thanks in advance for any good ideas.

Tom Kreutz

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Functions that return multiple calculated values

Tom,

You might want to substitute Dim y(1) for Dim y(2). As it is, y returns
an array with the elements 6,7,0; i.e., y(0)=6, y(1)=7 and y(2)=0.

Alan Beban

Tom Kreutz wrote:
Bob,

Thanks for your note. I want the function to return TWO calculated
results. John Walkenbach's book "Excel 2000 Power Programming with
VBA" says that that can be done by returning a variant array (as
opposed to an array of variants). Your note got me to trying the
simpler idea of just returning a standard array, which works fine!!
For example:

Function test()
Dim y(2) As Integer
y(0) = 6
y(1) = 7
test = y
End Function

This returns the values 6 and 7 in two different cells, as I wished.

Thanks for your help.

Tom

"Bob Phillips" wrote in message ...

Tom,

This works okay for me

Function test()
Dim y As Variant
ReDim y(1)
If Day(Date) 20 Then
y(1) = 1
Else
y(1) = 0
End If
test = y
End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tom Kreutz" wrote in message
. com...

I'm trying to write a function that will return multiple calculated
values. One way is to use the Array() function, which creates a
variant array, such as:

Function test()
Dim y As Variant
y = Array("a", "b")
test = y
End Function

However, I want to be able to output two CALCULATED values for y(1)
and y(2). If I try to do this in the code above, e.g. if ... then
y(1)=26, I get an error.

Am I missing somthing obvious?

Thanks in advance for any good ideas.

Tom Kreutz



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
Find a Match in Multiple Places & Return Multiple Values Toria Excel Worksheet Functions 3 June 24th 08 09:49 PM
Lookup in Multiple Columns, Return Multiple Values andy62 Excel Worksheet Functions 3 July 6th 06 02:36 AM
Multiple conditions and multiple return values Minerva Excel Worksheet Functions 3 February 16th 06 06:57 AM
Search multiple values to return single values JANA Excel Worksheet Functions 8 October 27th 05 04:26 PM
How to look up and return multiple values Wendy Excel Worksheet Functions 3 November 3rd 04 04:32 PM


All times are GMT +1. The time now is 08:52 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"