+ Reply to Thread
Results 1 to 11 of 11

Populate array to range of cells

  1. #1
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Populate array to range of cells

    Hi there,

    Good day!

    Referring to the code below, I have a Union of multiple non-contiguous columns stored to array.
    However, it only populates the data from first range for 5 columns as a result i.e. 5 columns with same data.

    I am suspecting it is due to the non-contiguous columns, however, I have no idea how to solve it.

    Appreciate any assistance!

    Thank you!

    Please Login or Register  to view this content.
    Edit: Added sample workbook.... Thank you!
    Attached Files Attached Files
    Last edited by hcyeap; 09-25-2015 at 01:15 AM. Reason: Added sample workbook

  2. #2
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: Populate array to range of cells

    do you want the result to be one column with all the values from the source sheet?
    If you wnt the columns same like on the source sheet just next to each other starting at A1 would it not be easier to copy them over?

  3. #3
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: Populate array to range of cells

    Quote Originally Posted by LordLoki View Post
    do you want the result to be one column with all the values from the source sheet?
    If you wnt the columns same like on the source sheet just next to each other starting at A1 would it not be easier to copy them over?
    Hi there,

    Thank you for the reply.

    If I understand correctly, are you suggesting to copy each range one by one?
    If yes, I can do that. I just thought I don't have to loop the copy steps for 5 times.
    My peer suggested to explore the array method, so I just give it a try.
    Please correct me if I am wrong.

    Thank you.
    Last edited by hcyeap; 09-24-2015 at 12:08 AM. Reason: TYPO

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2505
    Posts
    2,790

    Re: Populate array to range of cells

    I already beat you to this.
    Check out this thread where I had the same question.

    If you look at the array you've created you will see that it only contains the first range.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Populate array to range of cells

    I this particular case
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: Populate array to range of cells

    Quote Originally Posted by skywriter View Post
    I already beat you to this.
    Check out this thread where I had the same question.

    If you look at the array you've created you will see that it only contains the first range.
    Hi there,

    I just realized that I actually saw that thread when I googled.
    However, I still dont understand.

    Does it mean that I will need to do something like:
    HTML Code: 
    to make arrCopy becomes a range object?
    If yes, I tried, but I still can't get it though....

    Can assist to further guide me?

    Thank you!

  7. #7
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: Populate array to range of cells

    Quote Originally Posted by jindon View Post
    I this particular case
    Please Login or Register  to view this content.
    Hi Jindon,

    Thank you for the reply.

    I tried adding the code given by you and I got run-time error '13' type mismatch for the last line.
    Should I dim x?

    I tried though... but couldn't work.
    Maybe I missed out some other thing. Could you further point out for me?

    Thank you.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Populate array to range of cells

    OOps, should be
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: Populate array to range of cells

    [QUOTE=jindon;4199435]OOps, should be

    Hi jindon-san,

    Thank you very much for your reply.
    Your code worked.

    I made some changes:
    Please Login or Register  to view this content.
    If I understand correctly, you are using the index function which is similar to the index formula, 'evaluate' will be populating the data to the next row? and of course the last argument is the numbering of the columns.

    And then resize it? UBound(arrCopy, 1) is first dimension and UBound(arrCopy, 2) is the second dimension. correct?

    Thank you!

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Populate array to range of cells

    1)
    When you need to extract multiple rows/columns from Array, it should be 2d array for 2nd arg and 1d array for 3rd arg.
    Evaluate method will create 2d array from 1 to the last row in this case.
    i.e
    1,1
    2,1
    3,1
    4,1
    .
    .
    .

    2)
    For dumping the data from array, you will need to specify the size of cells(range) identical to the size of the Array.
    You will need to understand Resize property when dealing with VAB Arrays.

  11. #11
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: Populate array to range of cells

    Quote Originally Posted by jindon View Post
    1)
    When you need to extract multiple rows/columns from Array, it should be 2d array for 2nd arg and 1d array for 3rd arg.
    Evaluate method will create 2d array from 1 to the last row in this case.
    i.e
    1,1
    2,1
    3,1
    4,1
    .
    .
    .

    2)
    For dumping the data from array, you will need to specify the size of cells(range) identical to the size of the Array.
    You will need to understand Resize property when dealing with VAB Arrays.
    Got it!
    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Populate one array from another array and print new array as a range
    By Kaden265 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 07:52 AM
  2. Populate a range with an array from VBA
    By par0016 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2013, 05:39 PM
  3. How do I populate a range of cells with an array created in VBA?
    By par0016 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2013, 02:44 AM
  4. Populate 2D-array with non-contiguous range
    By Laksefar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2013, 06:37 AM
  5. Populate Array directly from Non-Contiguous range cells
    By Dominicus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2012, 02:52 PM
  6. Using array variable to populate range
    By sweep in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-19-2008, 11:14 AM
  7. Populating an array from a range, to populate a combobox.
    By spyrule in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-07-2006, 07:00 PM

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