+ Reply to Thread
Results 1 to 8 of 8

Populating an Array with Values

  1. #1
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Populating an Array with Values

    Let's say I want to create a two-dimensional array...

    arr(1 to 2, 1 to 2)

    ...with the following values:

    arr(1,1) = a
    arr(2,1) = b
    arr(1,2) = c
    arr(2,2) = d

    What is the easiest way to do it?

    I would like something like this:

    Please Login or Register  to view this content.
    Any suggestions?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Populating an Array with Values

    It is a good practice to assign variants to array as this will give flexibility on the type of data you are going to use.

    If you want a dynamic array
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Populating an Array with Values

    Hey AB33

    That's fine, but what is the easiest way to assign values to an array, regardless of type?

    i.e. is there a way to do it in one line instead of:

    arr(1,1) = a
    arr(2,1) = b
    arr(1,2) = c
    arr(2,2) = d

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Populating an Array with Values

    You mean like

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Populating an Array with Values

    Below is a 7 x 50 matrix

    I want to create an array with these values.

    What would be the most efficient way of doing that?


    37107287533902102798797998220837590246510135740250
    46376937677490009712648124896970078050417018260538
    74324986199524741059474233309513058123726617309629
    91942213363574161572522430563301811072406154908250
    23067588207539346171171980310421047513778063246676
    89261670696623633820136378418383684178734361726757
    28112879812849979408065481931592621691275889832738

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

    Re: Populating an Array with Values

    You could use something like this, but you would need to refer to the elements of the array with arr(x)(y) and the array will be 0-indexed.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

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

    Re: Populating an Array with Values

    Why do you need an array for that matrix?

    You could use string functions, eg Mid, to return the individual items.

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

    Re: Populating an Array with Values

    Just remembered, here's another way to create a 2D array.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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