LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default How to use the name for an array by using a variable?

See inline comment....

Your original post, and the answer I provided to it at the time, were not
lost. Here is a link to the Google archives for it...

http://groups.google.com/group/micro...460582ed4ea3de


Or, to make it independent of 0-Base/1-Base:

Sub Rothstein()
Dim X As Long
Dim Arr1 As Long
Dim Arr2 As Long
Dim VarArray As Variant
' We use VarArray to hold two elements,
' each of which is an array.
VarArray = Array(Array("A", "B"), Array("C", "D", "E", "F"))
' Note the syntax to address each array... a double pair of
' parentheses... the first set address which array member of
' VarArray we want, the second set addresses the element
' of the member array we want.
Arr1 = LBound(VarArray)
Arr2 = UBound(VarArray)


Good thought about making the assignments automatic; however, I think the
above line should more properly be this...

Arr2 = Arr1 + 1

The ArrX variables are indexes for the VarArray itself... Arr1 points to the
first stored array and Arr2 points to the second stored array (I did that to
make the "structure" similar to the OP's intial naming convention). While
your code works for the given example, the OP might find it more difficult
to extrapolate it if he chose to put 3 or more arrays into varArray. I think
he would be able to guess that a 3rd stored array would have Arr3=Arr2+1
more easily using my suggestion.

Rick


Debug.Print "******** Arr1 member elements ********"
For X = LBound(VarArray(Arr1)) To UBound(VarArray(Arr1))
Debug.Print VarArray(Arr1)(X)
Next
Debug.Print "******** Arr2 member elements ********"
For X = LBound(VarArray(Arr2)) To UBound(VarArray(Arr2))
Debug.Print VarArray(Arr2)(X)
Next
Debug.Print "******** DONE ********"
End Sub

Alan Beban


 
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
Dim an Array with a variable icdoo[_7_] Excel Programming 2 January 14th 06 03:26 PM
Array & variable David Excel Programming 5 March 22nd 05 09:49 AM
how can I see if an array contain a certain variable? Ronaldo[_2_] Excel Programming 3 November 17th 04 09:21 AM
about ARRAY variable Marek Excel Programming 3 September 13th 04 06:40 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


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