+ Reply to Thread
Results 1 to 12 of 12

change code to work with multidimensional array

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    change code to work with multidimensional array

    I have the following code (see below). THis code i found on this site stores files in a given directory into an array. What i want to do is change the array and make it multidimensional array so that i can store contents of the array into a column on the work sheet and i read somewhere that it was easier to do this via a multidimensional array...........

    so i want to take the contents of this array and use a statement like the following

    ws.Range(ws.Cells(1, 7), ws.Cells(ubound(test_array1), 7)).Value = test_array1

    or

    test_array1=ws.Range(ws.Cells(1, 7), ws.Cells(ubound(test_array1), 7)).Value


    to assign or read in array to worksheet



    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array......see code

    ok, i have been doing some reading.......you can only

    redim preserve the "last" dimension in a multi-dimensional array so changing this code to a multidimensional array wont work.

    any ideas how to get the contents of this array that is in the code to go to a single column on a worksheet?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: change code to work with multidimensional array

    Please Login or Register  to view this content.
    Last edited by shg; 08-06-2011 at 05:25 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array

    Awesome!!!!!!!!!!!!!!!!!!! Perfect............thanks. I just checked it and it works great!!!!!!

    thanks!!!!!!!!!!!!!

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array

    one quick question..........how do i now read the contents of the sheet back into the array?

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: change code to work with multidimensional array

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array

    i could not get that to work......i get a type mismatch error............. any ideas?

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: change code to work with multidimensional array

    please check attachment
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array

    hi watersev,

    in the file you sent the range is horizontal...........i was hoping to take data from a column and put collumn data into array.

    but i did not know about the horizontal assignment.........i can use that as well.

    Do you know how to do it for a "column" of data?

    thanks!

  10. #10
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,677

    Re: change code to work with multidimensional array

    watersev, when i take your previous code and try to then take the array and put the array contents into the work sheet using code below..........only 1 entry gets put in worksheet

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: change code to work with multidimensional array

    please check attachment for vertical range layout
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: change code to work with multidimensional array

    Quote Originally Posted by welchs101 View Post
    watersev, when i take your previous code and try to then take the array and put the array contents into the work sheet using code below..........only 1 entry gets put in worksheet]
    Please Login or Register  to view this content.
    This shows that you have 1 row of data with some number of columns, example A1:G1

    Please Login or Register  to view this content.
    Here you determine range starting from M1 and resize it to be one cell M1 (ubound(x)=1). So when you paste X array you get 1 value.
    In order to get all array data you need to use Ubound(x,2) instead:

    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