+ Reply to Thread
Results 1 to 5 of 5

write a collection to a range

  1. #1
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    write a collection to a range

    I have a collection (2D, 1 column to make it simple). Can I directly write it to a range or I need to convert it to an array to do that? Many thanks!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: write a collection to a range

    A collection cannot be written directly to a work sheet.

    This code will take the elements of a collection and write them to a sheet. (Usually a collection holds objects, not values.)

    Please Login or Register  to view this content.
    I'm curious about your collection. Frequently, collections hold objects, not variables, so writing them to a sheet involves a property of the items in the collection, not the item itself.

    Also, there is no such thing as a 2D collection. All collections are one dimensional.
    Last edited by mikerickson; 01-09-2016 at 09:02 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: write a collection to a range

    Quote Originally Posted by mikerickson View Post
    A collection cannot be written directly to a work sheet.

    This code will take the elements of a collection and write them to a sheet. (Usually a collection holds objects, not values.)

    Please Login or Register  to view this content.
    I'm curious about your collection. Frequently, collections hold objects, not variables, so writing them to a sheet involves a property of the items in the collection, not the item itself.

    Also, there is no such thing as a 2D collection. All collections are one dimensional.
    Thanks Mike! I use the collection to get unique values for a combo box items. Good to know there is only one dimension in collections. I can only deal with one column

    However I always have to redim preserve and then transpose the array to get the values, even for 1 column:
    Please Login or Register  to view this content.
    Last edited by aprildu; 01-11-2016 at 12:14 AM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: write a collection to a range

    Thanks Mike! I use the collection to get unique values for a combo box items.
    Perhaps you'd be interested in these codes. Neither uses a collection.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: write a collection to a range

    Quote Originally Posted by mikerickson View Post
    Perhaps you'd be interested in these codes. Neither uses a collection.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks for the codes. Brilliant! I am still going to use the collections this time though. Try to force myself to learn new ways of doing things.
    Last edited by aprildu; 01-11-2016 at 03:38 PM.

+ 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. Replies: 4
    Last Post: 10-30-2015, 01:30 PM
  2. [SOLVED] Performance of iteration through Words collection degrades as collection gets bigger
    By 6StringJazzer in forum Word Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2014, 09:44 AM
  3. How to write a macro about Looping over collection
    By Xiaojiang in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-30-2011, 01:53 AM
  4. Replies: 2
    Last Post: 12-23-2011, 11:04 AM
  5. Named Range Not In DAO Tabledefs Collection
    By chergh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2008, 09:13 AM
  6. Collection from Range, tag cells on error
    By nowon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2006, 08:40 PM
  7. [SOLVED] Range collection
    By Ernst Guckel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2005, 03: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