![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Location: Forest, VA
Posts: 45
|
Hi,
I searched the documentation I have and this web site but, I still cannot figure out how to declare a function that returns an array (in my case a array of strings) of an un-predetermined size. Currently, I use "Public Dim myArray() As String" and then ReDim the array in my Sub. This works but I would much rather declare the Sub as a Function that returns the array of strings. Does anyone know how to do this? Thanks in advance for the help. Regards, Vlip |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi Vlip,
Simply declare the function as Variant, then assign the array to the function value. A function cannot return an array. However, a function CAN return a variant that CONTAINS an array. I realize that this is a vague distinction, but it workds. For example: Function StrArray( args.. ) As Variant Dim myArray() As String ReDim myArray(50) 'code that sets values into myArray and/or 'ReDims myArray StrArray = myArray End Function
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Location: Forest, VA
Posts: 45
|
Thank you very much! I knew I could do what you suggested. I guess the answer I was looking for is "a function cannot return an array". It seems to me a limitation of VB.
Vlip |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|