+ Reply to Thread
Results 1 to 6 of 6

Somehow turned 1-dimensional array into 2D array .....dont know how

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

    Somehow turned 1-dimensional array into 2D array .....dont know how

    Question:
    I have this 1D array that after i "sort" it using my own sort function the array comes back as 2D. Now how do i know it comes back as 2D.

    If i dont do my special sort function i can reference the array as "array_file1(x)" where x is variable.

    If i do my special sort function i MUST reference the array as "array_file1(x,1)" where x is variable.


    I am enclosing the part of my code that does the sort and does the initializing of the arrays.........



    Now in my sort i paste the array into the worksheet and then do the sort then read the worksheet into array. So my guess is reading the worksheet data inot the array is somehow causing this change.........but i dont understand why. Her eis the command i use to store the values into the array from the worksheet

    Please Login or Register  to view this content.


    so my question is why does my array go from 1d to 2d and what command do i need to change to keep it 1d. its not that the 2d is bad its just that this was unexpected and took me a little while to figure out.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Somehow turned 1-dimensional array into 2D array .....dont know how

    I think if you assign a range of values to a variant it automatically becomes a 2D array.

    I guess the workaround would be to read the range values in one by one, but if you can live with the array being 2D then it's a neater solution.

  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: Somehow turned 1-dimensional array into 2D array .....dont know how

    Why not use a simple sort routine that doesn't convert the array to 2D? I posted one for you a few days ago.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Somehow turned 1-dimensional array into 2D array .....dont know how

    You transform an array into a Range (in a worksheet).
    A Range is always 2-dimensional.
    If you read a Range from a worksheet into an array the array will have the same dimensions as the Range (2-dimensional).



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

    Re: Somehow turned 1-dimensional array into 2D array .....dont know how

    thanks to all who responded.


    shg,
    I created this sort method before you pasted the code on the sort. I will look at the sort info you posted again and use it.

    thanks.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Somehow turned 1-dimensional array into 2D array .....dont know how

    To turn a range into a 1-dimensional 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