+ Reply to Thread
Results 1 to 6 of 6

Iterate Array Names with Integers

  1. #1
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Iterate Array Names with Integers

    Suppose you have 3 variant Arrays, named sArrPos1, sArrPos2, and sArrPos3.

    What is the syntax for using an integer variable to specify which of the three to work with?

    e.g.

    Please Login or Register  to view this content.
    I want to work with sArrPos1 first, then sArrPos2, then sArrPos3, but can't hard type them.

    Thanks,
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Iterate Array Names with Integers

    There's isn't one.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Iterate Array Names with Integers

    Bummer.

    What if I sent all of my data to one array dimensioned as 1 to n, 1 to 3? So:
    Please Login or Register  to view this content.
    . Now I've dynamically sized a (1 to n, 1 to 3) array, correct? If I find what I'm looking for in the '2nd Column' position of the array, can I send just that column to the worksheet?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Iterate Array Names with Integers

    Declare a variant array with thee elements.
    Assign individually column values to one element in the array for each column.. This creates an array of arrays.
    Reference the columns within the array by index number.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Iterate Array Names with Integers

    AlphaFrog's approach would give you a jagged array. "Jagged", because there might be a different number of elements in the sArrPos(1) than in sArrPos(2).

    It sounds like you would be comfortable with that approach, but you can access whole columns (or rows) of an array like this.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Iterate Array Names with Integers

    Thank you both. In this case, all three arrays are static and will always be the same number of elements (I always see this as the array's 'depth').

    Alpha - I'm off an running with the array of arrays approach. Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replace Strings with Zeros/Integers in an Array?
    By xlbee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2013, 02:48 PM
  2. [SOLVED] Iterate Through Names, list unused: Type Mismatch with Cells.Find
    By tlafferty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 04:03 PM
  3. Converting Array to Integers
    By cporter5 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-29-2010, 12:23 AM
  4. Printing array values as integers not doubles
    By sunita in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2010, 04:24 PM
  5. Formatting Integers as Month's Names
    By rvExcelNewTip in forum Excel General
    Replies: 6
    Last Post: 01-07-2007, 05:46 PM

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