Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Accessing individual items in an array returned by a function

In VBA, I create the following function that returns an array of
length 3.

Public Function RegionSizeStyle() As Variant
Dim results(2) As Variant
Region = "JP"
Size = "Small"
Style = "Core"

results(0) = Region
results(1) = Size
results(2) = Style

RegionSizeStyle = results

End Function

In Excel, if I select three cells in the same row, enter
=RegionSizeStyle() into the first one and then hit CTRL-SHIFT-ENTER,
the cells are filled with RegionSizeStyle(0), RegionSizeStyle(1), and
RegionSizeStyle(2) respectively, just as I would expect.

However, if I select a SINGLE cell and then try to extract a single
item form the array that is returned by typing =RegionSizeStyle()(1),
I get a #REF regardless of whether I finish by entry by hitting ENTER
or CTRL-SHIFT-ENTER. What is the problem? Is it just my syntax or is
there a deeper problem?

Thanks in advance for your assistance.

Thomas Philips
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Accessing individual items in an array returned by a function

Got it by modifying the keywords in my Google search - The correct
syntax is
=Index(RegionSizeStyle(), i)
for i=1, 2 or 3.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default Accessing individual items in an array returned by a function

Hi,

You need to type just RegionSizeStyle() to fetch the first value. I think
you are calling the function in a wrong way.

HTH,
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


" wrote:

In VBA, I create the following function that returns an array of
length 3.

Public Function RegionSizeStyle() As Variant
Dim results(2) As Variant
Region = "JP"
Size = "Small"
Style = "Core"

results(0) = Region
results(1) = Size
results(2) = Style

RegionSizeStyle = results

End Function

In Excel, if I select three cells in the same row, enter
=RegionSizeStyle() into the first one and then hit CTRL-SHIFT-ENTER,
the cells are filled with RegionSizeStyle(0), RegionSizeStyle(1), and
RegionSizeStyle(2) respectively, just as I would expect.

However, if I select a SINGLE cell and then try to extract a single
item form the array that is returned by typing =RegionSizeStyle()(1),
I get a #REF regardless of whether I finish by entry by hitting ENTER
or CTRL-SHIFT-ENTER. What is the problem? Is it just my syntax or is
there a deeper problem?

Thanks in advance for your assistance.

Thomas Philips

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 results not returned JRM-drof Excel Worksheet Functions 2 June 27th 06 06:46 PM
Accessing specific items in a range droopy928gt Excel Programming 3 January 8th 06 06:48 PM
PivotTable Does not refresh individual items Nick O[_2_] Excel Programming 0 August 23rd 05 10:33 AM
How Do I Reference Individual Dropdown Menu Items in VBA? FuadsCurse Excel Programming 3 May 3rd 05 02:41 PM
Preformatted array returned by custom function Asif[_3_] Excel Programming 9 December 4th 03 06:31 AM


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