+ Reply to Thread
Results 1 to 15 of 15

New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Unhappy New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    I am trying to convert a 1D array to a 2D. Below is where I am up to so far. I just need help with the Redim Preserve line. Can any of you nice array experts help out please?

    Please Login or Register  to view this content.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Can't you just use the transpose function?

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Quote Originally Posted by Kyle123 View Post
    Can't you just use the transpose function?
    Unfortunately no.

    (I need the array to fill a ListBox and it seems there are issues with trying to .List a 1D array on a ListBox - but that's a topic for other threads).
    Last edited by mc84excel; 05-24-2013 at 03:33 AM. Reason: Bolded...In case anyone else stumbles on this thread and gets diverted off this thread question

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Yeah have a look at my comment on that thread. Transposing gives you a 2 d array, wheres the issue?

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    ms84excel, could you attach a file with your troubled ListBox

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Quote Originally Posted by Kyle123 View Post
    Yeah have a look at my comment on that thread. Transposing gives you a 2 d array, wheres the issue?
    Sorry Kyle. It doesn't work for me.

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Quote Originally Posted by nilem View Post
    ms84excel, could you attach a file with your troubled ListBox
    Hello nilem,
    1. It would mean having to remove a large amount of confidential data. (I may have to go down that route if I cant convert a 1D array to a 2D array).
    2. No offence intended - but would you mind posting this comment in the other thread? I would like to keep this thread focused on converting a 1D array to 2D. Thanks.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    What does:
    Sorry Kyle. It doesn't work for me.
    Actually mean? In what way doesn't it work for you? Application.Transpose transposes an array:
    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Quote Originally Posted by Kyle123 View Post
    What does:


    Actually mean? In what way doesn't it work for you? Application.Transpose transposes an array:
    Please Login or Register  to view this content.
    Sorry that is my fault for not clarifying.
    1. In my thread about 1D arrays to a ListBox, I have explained what happened when I tried your suggestion.
    2. No offense intended - but would you please keep any posts relating to the "1D array to a ListBox" issue on that thread - not this one (which is meant to be about converting a 1D array to a 2D array...)

  10. #10
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Everyone,

    Please please keep your posts on this thread relating to the topic (Converting a 1D array to a 2D array).

    If you have any suggestions on how to populate a ListBox with a 1D array, please post them in the other thread.

    Thank You!
    Last edited by mc84excel; 05-24-2013 at 03:34 AM.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Eh? I'm not talking about listboxes, in this thread I'm talking bout conveting a 1d array to 2d

  12. #12
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Quote Originally Posted by Kyle123 View Post
    Eh? I'm not talking about listboxes, in this thread I'm talking bout conveting a 1d array to 2d
    I apologise. It is my fault for misunderstanding.

    I can transpose an array but how does that make a 1D array = 2D?

    In my opening post, I am trying to add a 2nd row (of empty values) in order to make the 1D array to 2D.

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Just put a break point in and inspect it in the locals window. Transpose works due to how Excel understands rows and columns, rows are single dimensioned, columns have 2 dimensions.

  14. #14
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    I tried transposing the 1D array but it didn't make it 2D. (Locals window still showed Variant/Variant(1 to 3).

    I solved the sub - the code below will make a 1D array into a 2D array (Locals window will show Variant/Variant(1 to 3, 1 to 2) after running the sub).

    This adds the 1D array contents to the 1st column. If you need the 1D array contents to the 1st row instead then change the last line of the sub to transpose the varArrayOutput.

    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to arrays-Convert 1D array to 2D (Need help on 1 line of code)

    Updated version. Note the module is set to Option Base 1

    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)

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