+ Reply to Thread
Results 1 to 3 of 3

array names declared on the fly

  1. #1
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    array names declared on the fly

    Hello,

    What I'm trying to do is probably best if a multi-dimensional array is used, but I want to keep it as simple as possible, and I think this is simpler... at least for me.

    Okay, so I have Row #1 with 12 cells of data.
    I want to put this into an array, which is simple enough: Dim row1array(1 to 12) as string

    But say I have 12 ROWS, and I want to dynamically create the array names.
    1) Is there a way to do this in the "DIM" declaration inline?
    2) Or even if I created the names first in a separate for loop... how would I dereference the string variable I created in the DIM declaration?

    i.e.
    for loop creates the following array names:
    row1array
    row2array
    row3array
    This names are temporarily stored in the variable "myTempArrName"

    Now when i tried to declare my array I want to do the following:
    Dim myTempArrName(1 to 12) as string <== How to I deference myTempArrName to actually make the array row1array(1 to 12), row2array(1 to 12), etc...

    Many thanks

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: array names declared on the fly

    Hi GunNam,

    I think you are abstracting too hard and cross dimensioning your variable types. I'm not sure the compiler will allow you to Dim a variable string into an array.

    I think you have to simply load your values into a 2 dimension array and work with it as that. I think this will be much easier too. You can then have the first number in your array as the row number and the second as the column number. This sounds a lot like Cell notation.

    If you want the best site on arrays, look at: http://www.cpearson.com/excel/VBAArrays.htm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    09-28-2010
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: array names declared on the fly

    Thanks Marvin,

    After I reacquainted myself with a 2 dimensional array... this is definitely the simpler way. I was trying to complicate things with a simple 1 dim array.

    Thank you for your input, I'm on the right path.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1