+ Reply to Thread
Results 1 to 11 of 11

Quick Array question - Copy array to another array then resize?

  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

    Exclamation Quick Array question - Copy array to another array then resize?

    Hello all,

    I am new to arrays and have a urgent need for the following scenario:

    I have a variant 2 dimensional array (2 columns by X number of rows).

    I need to somehow separate out the values from the first column of the array. (these values will be used to fill a listbox on a form - not that it matters).

    Would it be possible to clone the array to a 2nd array and then resize the 2nd array so it only has the first column instead of both? (If anyone has a quicker/more efficient solution - I am open to suggestions).
    *******************************************************

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

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

  2. #2
    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: Quick Array question - Copy array to another array then resize?

    I found CopyArraySubSetToArray on Chip Pearsons website http://www.cpearson.com/excel/vbaarrays.htm but I am uncertain as to how to use it and whether it is even what I need.

    What do I need to enter for the the 3 long values?

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

    Re: Quick Array question - Copy array to another array then resize?

    Try to use the WorksheetFunction.Index
    Or you can fill listbox by two-dimensional array, just set the width of the second column of listbox to 0.

  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: Quick Array question - Copy array to another array then resize?

    Quote Originally Posted by nilem View Post
    Or you can fill listbox by two-dimensional array, just set the width of the second column of listbox to 0.
    Thanks nilem. I like the sound of your second suggestion. I am new to arrays. What code do I need to set the second column to 0?

    (Below is the form sub I have currently if that is any help):
    Please Login or Register  to view this content.

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

    Re: Quick Array question - Copy array to another array then resize?

    try it (not tested)
    Please Login or Register  to view this content.

  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: Quick Array question - Copy array to another array then resize?

    Hello nilem. It worked straight away. Thank you +1

  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: Quick Array question - Copy array to another array then resize?

    Hello nilem. One minor problem. The code you provided in post #5 fills the Listbox1 but it doesn't fill it with a two dimensional array with the second column hidden (refer post #3)

    Background information:
    I need to read a 2 column range from a closed workbook. The listbox is filled with the second column of this range/array. I need to keep the original range/array data because I somehow need to return the value selected in the listbox to read the corresponding first column.

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

    Re: Quick Array question - Copy array to another array then resize?

    Attach a small sample file with your form and listbox

  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: Quick Array question - Copy array to another array then resize?

    Quote Originally Posted by nilem View Post
    Attach a small sample file with your form and listbox
    Thanks nilem. OK.

    Create a new XLSX file and put some dummy data into the first 4-5 rows of column A & column B. Name the sheet "employer10" and save and close the workbook. (This is a dummy workbook that will be used to test the code).

    Now create a new XLSM.
    Copy the code below into a new form. Add a Listbox and a Command button to the form. The Command button should be called OKButton.
    You will need to add a public const for sServerFolderProgram & sServerFileDatabaseExcel. The first const should point to the XLSX folder location (without the last "\") and the second const should be the filename of the XLSX file.

    Please Login or Register  to view this content.

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

    Re: Quick Array question - Copy array to another array then resize?

    mc84excel,
    Thanks for the detailed instructions
    I found a suitable example, and hope this will help you
    Attached Files Attached Files

  11. #11
    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: Quick Array question - Copy array to another array then resize?

    Quote Originally Posted by nilem View Post
    mc84excel,
    Thanks for the detailed instructions
    I found a suitable example, and hope this will help you
    The example workbook worked. Thanks +1

+ 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