+ Reply to Thread
Results 1 to 2 of 2

How do I populate a range of cells with an array created in VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    65

    How do I populate a range of cells with an array created in VBA?

    I am brand new to VBA (taught myself) and this is probably a very simple and stupid question but I have an array in VBA and I can't for the life of me get it into the ranges I specify. Instead it just populates the cells I have specified with the first value of the array. The even more perplexing part is that when I manually place them in the cells (aka range("A1") = MyArray(1), range("A2") = MyArray(2)) it works perfectly. Obviously that isn't what I want to do though.

    I currently am trying to populate the range using this:

    Range("A1:A20") = MyArray

    I have also tried:

    Range("A1:A20").Value = MyArray

    I have already transposed MyArray and it is dimmensioned as Dim MyArray(1 to 20) as variant.

    Please give me something, I am sure this is so simple, but I am completely at a loss.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: How do I populate a range of cells with an array created in VBA?

    Sub arraytorange()
    arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Range("E1:N1") = arr
    Range("E1:E10") = Application.Transpose(arr)
    End Sub
    If solved remember to mark Thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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