Results 1 to 5 of 5

write a collection to a range

Threaded View

  1. #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.)

    Dim i As Long
    Dim myArray as Variant
    
    With Sheet1.Range("A1").Resize(myCollection.Count, 1)
        Redim myArray(1 to .Rows.Count, 1 to .Columns.Count)
    
        For i = 1 to myCollection.Count
            myArray(i, 1) = myCollection(i)
        Next i
    
        .Value = myArray
    End With
    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.

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. 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