+ Reply to Thread
Results 1 to 6 of 6

Populate a range with an array from VBA

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

    Populate a range with an array from 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 nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Populate a range with an array from VBA

    maybe this example will help you
    Please Login or Register  to view this content.

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Populate a range with an array from VBA

    Apparently this was of no help so I deleted it.

    Have a great day.
    Last edited by Mordred; 04-14-2013 at 03:21 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

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

    Re: Populate a range with an array from VBA

    Nothing here worked. But I did get this to work:

    Please Login or Register  to view this content.
    When I eliminate the first transpose, it places the first value in all 17 columns.
    When I eliminate the second transpose aka Range("A4:A20") = arr, it places the first value in all 17 columns also.
    When I eliminate the both transpose functions it doesn't place any values in the range.

    Any other ideas?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Populate a range with an array from VBA

    This will work.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Populate a range with an array from VBA

    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ 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