+ Reply to Thread
Results 1 to 9 of 9

Moving dictionary items to an 2D array that can be placed into worksheet quickly

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Moving dictionary items to an 2D array that can be placed into worksheet quickly

    Hi all,

    From what I have learned at this site and books is that is you want to read from or write to a range of cells in excel quickly you have to use a "variant" array dimensioned something like this.

    Dim example_array (1 to 400, 1 to 1)

    One can assign the contents of this array to an appropriate range very very quickly.

    Here is my question/problem:

    I have a dictionary of items. The dictionary is created in the following manner....nothing fancy.

    Please Login or Register  to view this content.

    Now I need some way of getting the dictionary items out and into an array like the one I mentioned above that can be placed into a range quickly.


    if I use this code

    Please Login or Register  to view this content.
    then junk_array become an array of the dictionary items but its not of the appropriate format and I can not put the contents of this array into a range of cells quicky.

    So my question is how to get items out of a dictionary and into a variant array type that I can then place the contents into a range quickly.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    Quote Originally Posted by welchs101 View Post
    if I use this code

    Please Login or Register  to view this content.
    then junk_array become an array of the dictionary items but its not of the appropriate format and I can not put the contents of this array into a range of cells quicky.
    Why? It's just an array

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    sorry but I don't understand your question.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    You specify that you cannot put the the array returned by the items property of the dictionary object directly into a range.

    My question is simply why can't you? Have you tried it?

    I would guess that in our example that the junk_array is simply an array of strings - there's no reason that you can't populate the worksheet directly with it

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    ok. can you provide the code that you would use to place junk_array into sheet1 starting in cell C1.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    thanks.

    just a note. Application.transpose wont work correctly if you have too many elements in the array. I forget what the number is .......I have run into it twice for large files.




    So I have to transpose the array to paste it into range.........ok.

    thanks.

    I really appreciate your help.........

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    So I have to transpose the array to paste it into range
    Yes, just like any array, the dictionary is a bit of a red herring since it isn't relevant

    It's about 65k elements, it's fast to just create a 2d array and read the elements in before writing it to the sheet though if you think it may be an issue

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Moving dictionary items to an 2D array that can be placed into worksheet quickly

    Thanks.

    I think this is what I have done in the past is create a 2D array and then take data "out" of dictionary and put into array like the following:


    Please Login or Register  to view this content.

+ 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. help assigning elements of dictionary to array and then pasting array into worksheet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-05-2013, 10:37 AM
  2. Create array with distinct items using scripting.dictionary
    By icyrius in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-06-2013, 04:36 PM
  3. [SOLVED] Adding items to Dictionary object
    By Eduard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2013, 04:39 AM
  4. looping through items in a dictionary
    By Abe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2006, 05:45 AM
  5. Replies: 4
    Last Post: 01-11-2005, 05:06 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