Consulting

Results 1 to 3 of 3

Thread: Appending arrays

  1. #1
    VBAX Regular mleary2001's Avatar
    Joined
    Feb 2006
    Location
    Missoula
    Posts
    12
    Location

    Question Appending arrays

    Is there an "append" operator or function in VBA for appending one array to another?

    Thanks in advance,
    Mike

  2. #2
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    I am not familiar with Mac per se, but not that I know of.

    You can redeclare the dimensions of an array to include the dimensions of the other..

    Say you have:
    [VBA]
    Dim myArray()
    Dim lngCount as Long

    lngCount = range("A1")

    ReDim myArray(1 to lngCount)

    [/VBA]

    Then you populate the redim'd array with potentially another array if needed

    [VBA]

    For x = 1 to UBound(MyArray)
    MyArray(x) = 'something
    Next x
    [/VBA]
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  3. #3
    VBAX Regular
    Joined
    Jan 2006
    Posts
    56
    Location
    Hi Mike,
    Short answer is no, not directly. In addition to XLGibbs post on ReDim, I'd add that you'll need to use the optional keyword "Preserve" in order to get the existing elements of your array saved during the ReDim process, otherwise, they'll get blown away.

       ReDim Preserve A(10)
    to re-dimension the array A to 10 elements, saving the existing values.


    Ed

Posting Permissions

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