+ Reply to Thread
Results 1 to 6 of 6

store data in memory array and then paste to sheet all at once

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    store data in memory array and then paste to sheet all at once

    Hi all,

    can I store data in an array in memory and then put that into a sheet all at once?
    I've got a sheet that gets data from webqueries - the unique identifier is in column A and retrieved data is in subsequent columns.
    For example:

    in column A, from cell 2 down, I have a list of classes
    'math, science, english, biology' etc
    in columns B - F, row 1, I have student names
    'jack, sophie, peter, janet, peter'

    The webscrape will retrieve math scores for all students - I want to store those scores into an array in memory, then do the next webscrape (science scores) etc.
    So in the end I'll have an array with data, that I just want to fill into the sheet all at once.

    For reasons too complicated to explain, I can not put the data in the sheet every time I get the scrape result.

    How would I go about and do this - seems to me like a simple 2-dimensional array, but I've got two challenges.
    a) the order of the classes keeps changing
    b) the number and order of the students keeps changing

    How would I create an array so I know to put 'science' in the second row of the array and 'peter' in the 5th column of the array?
    Any help is much appreciated!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: store data in memory array and then paste to sheet all at once

    You can load data from a range in to array and vice versa. The data will be displayed in order as they are loaded from a range in to an array and back in to a range.

    E.g

    Please Login or Register  to view this content.
    Last edited by AB33; 08-15-2015 at 05:18 AM.

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: store data in memory array and then paste to sheet all at once

    Thanks, AB33 - so in my example, I would say
    Please Login or Register  to view this content.
    Then, how would I paste that back into A1 after putting data into x(2,4) for example?

    Also - is there an easy way to search the name in the first row of the array or do I have to loop?

    So let's say I retrieve the science grades, I will know science is in row 3, but I won't know in which order the names will be, so I'll have to look up the name in the first row of the array.
    Last edited by JasperD; 08-15-2015 at 05:35 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: store data in memory array and then paste to sheet all at once

    Let's say, you want to put the result in F6

    Please Login or Register  to view this content.
    Mind you: loading a range in to an array ALWAYS produces a TWO dimensional array.
    If you want to retrieve a particular element with in the array, you need to loop through the array. Each element with in the array has an index number.
    Last edited by AB33; 08-15-2015 at 05:44 AM.

  5. #5
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: store data in memory array and then paste to sheet all at once

    OK, this works great, thanks a lot.

    Now for another challenge - I put the same range in two arrays

    ar1 and ar2

    ar1 contains the values I want to put in the sheet, so I do that by saying: "Sheet3.Range("A5").Resize(Ubound(ar1), Ubound(ar1, 2)) = ar1"
    However, the values in ar2, I want to put as cell comments in the corresponding cells.

    Is there an easy way to do this, or will this be looping?

    Thanks again for any assistance!

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: store data in memory array and then paste to sheet all at once

    Hi JasperD,
    I am not quite sure I understand your question. Cell comments are properties of range, so each cell has its own comment property. I do not see how to get around other than, I am afraid the dreaded word, "Looping". If you want to play with the properties and methods of a range, an array will not help as you need to access of each of these through a range. An array is simple a collection of data and these data share the same variable. It speed up the process of looping as these collections of data act as a single item in unison.

+ 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] Dynamic Changing Data, Based on Criteria Store in Array, Sum array and store in Cell
    By penbeacho in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-28-2015, 10:31 AM
  2. Can I store an array of data within a table?
    By krabine in forum Access Tables & Databases
    Replies: 3
    Last Post: 01-14-2015, 12:04 PM
  3. Replies: 3
    Last Post: 10-05-2014, 11:48 AM
  4. [SOLVED] How to store variable data into an array - help on arrays
    By mandukes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2014, 09:24 AM
  5. Store data into an array if/based on specific conditions met
    By exlgh91 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2013, 11:38 AM
  6. How to store strings in a array and paste them in individual cells in MS ACCESS..
    By shobinp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2012, 03:36 AM
  7. [SOLVED] How Do You Take Data Off A Sheet and Store It In An Array
    By Raleigh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2006, 04:50 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