+ Reply to Thread
Results 1 to 8 of 8

multi-dimensional array to single column

  1. #1
    Registered User
    Join Date
    08-12-2011
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Thumbs up multi-dimensional array to single column

    Hi,

    I need a macro that allows me to select a matrix of cells and convert it into a single column. My matrix is like so:

    1a 1b 1c 1d 1e 1f
    2a 2b
    3a 3b 3c 3d

    I want to change this into a single column like this:

    1a
    1b
    1c
    1d
    1e
    1f
    2a
    2b
    3a
    3b
    3c
    3d

    and paste it in a selected location. Thanks so much.
    Last edited by pcm2004; 08-12-2011 at 08:38 PM. Reason: cleanup format

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: multi-dimensional array to single column

    Hello & Welcome to the Board,

    Try this...

    The results are pasted to column H with you sample data

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: multi-dimensional array to single column

    'ROWS TO COLUMNS
    Here's a macro for taking random rows of data and putting them into a single column of values.
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    08-12-2011
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: multi-dimensional array to single column

    Thanks Jeff and Jerry Beaucaire!

    Jerry's code did exactly what I had in mind. Thanks to both of you for prompt response. Your help makes this forum terrific!

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

    Re: multi-dimensional array to single column

    There's no need copying (that slows down the macro):

    Please Login or Register  to view this content.



  6. #6
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: multi-dimensional array to single column

    Hi

    I was not sure what variable type sn was so I
    made it a variant.

    When I run your code I get the following values in a column. Please
    note the blank between 2b and 3a

    1a
    1b
    1c
    1d
    1e
    1f
    2a
    2b

    3a
    3b
    3c
    3d

    If I debug each co1 thru the for loop I see

    ?UBound(sn)
    ?c01
    |1a|1b|1c|1d|1e|1f
    ?c01
    |1a|1b|1c|1d|1e|1f|2a|2b||||
    ?c01
    |1a|1b|1c|1d|1e|1f|2a|2b|||||3a|3b|3c|3d||

    If I look at each element in the variant sn I see

    ?sn(12)
    3d
    3c
    3b
    3a

    2b
    2a
    1f
    1e
    1d
    1c
    1b
    1a

    I am not certain if my variable definition have introduced a problem.

    Dim sn As Variant
    Dim j As Integer
    Dim c01 As String

    regards
    John

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

    Re: multi-dimensional array to single column

    Please, use code tags....

    You might use:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: multi-dimensional array to single column

    That worked!

    regards
    John

+ 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