Results 1 to 4 of 4

Thread: Quick way to populate cells from arrays ?

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Question Quick way to populate cells from arrays ?

    I have half a dozen arrays that populate a sheet.
    At the mo I am populating the sheet in the worst (slowest) possible way, i.e. using acivecell.offset and then moving down a line and repeating etc.

    Theres a much better way to do this .. but I can't remember it.

    Can anyone remind me ?

    Ta

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Quick way to populate cells from arrays ?

    You can copy the whole array to a range of the same dimensions.
    Here's a simple example
    VB Code:
    1. Sub CopyArrayDemo()
    2. Dim aMyData()
    3. Dim x, y
    4.  
    5.     ReDim aMyData(1 To 5, 1 To 2)
    6.    
    7.     For x = 1 To 5
    8.         For y = 1 To 2
    9.             aMyData(x, y) = x * y * 10
    10.         Next y
    11.     Next x
    12.    
    13.     ThisWorkbook.Worksheets(1).Range("A1:B5").Value = aMyData
    14. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Quick way to populate cells from arrays ?

    Thats a good idea .. although 2 elements of the array I have to check and do a "If this value then do this else do this" scenario, so I'm not sure if that scuppers things.
    I'll have a play around and see what I can come up with.

    Cheers Kenny !

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Quick way to populate cells from arrays ?

    I can't recall if I did this and got it working, but if your range is of one cell I think you can paste in an single array of values horizontally.

    something like:
    Code:
    set rng = sht.cells(1,1)
    rng=ary()

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width