+ Reply to Thread
Results 1 to 5 of 5

New to arrays-Create two column array with different column order to sheet?

  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

    Question New to arrays-Create two column array with different column order to sheet?

    UPDATE: Yes, I know the obvious solution is to alter the worksheet column order instead. But I can't (long story) hence this thread.

    I am new to arrays and wish to achieve the following:

    I have worksheet range in Column A & Column B that I want to read into an array of 2 columns wide, X (variable) rows deep. Now for the catch. I need the array to have Column B data in the first array column and Column A data in the second array column.

    How do I do this? (short of slowly building the array individual record by individual record)
    • Would it be possible to copy A & B columns and then transpose the column order in the array? (Don't laugh. I am new to arrays).
    • Would it be possible to somehow read Column B values and then Column A values when creating the array?
    • Messier. Would it be easier to build two arrays (one column each) and then 'join' these together in the order I want??
    Last edited by mc84excel; 05-02-2013 at 12:05 AM. Reason: prevent the obvious question being asked
    *******************************************************

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

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

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

    Re: New to arrays-Create two column array with different column order to sheet?

    just as an example
    Please Login or Register  to view this content.
    Try, it works very fast

  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-Create two column array with different column order to sheet?

    thanks for the reply nilem but the code you provided switches the columns on the sheet.

    I wish to read the sheet values (not reading by individual values e.g. For/Next) then switch the array columns.

  4. #4
    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-Create two column array with different column order to sheet?

    Am marking this thread as solved. (I only needed this column order in the vba array to make a VLOOKUP possible but this was unnecessary - it was resolved through an alternative approach)

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: New to arrays-Create two column array with different column order to sheet?

    you can also do this using application.index
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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