Merge two 1d arrays into one 2d array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moishy101
    New Member
    • Feb 2012
    • 46

    Merge two 1d arrays into one 2d array

    How can I merge two one dimensional arrays into one two dimensional array?

    for example:
    arrOne = Split("Apple,Or ange,Grape,Lemo n", ",")
    arrTwo = Split("Green,Or ange,Red,Yellow ", ",")

    arrThree should return:
    ("Apple", "Green")
    ("Orange", "Orange")
    ("Grape", "Red")
    ("Lemon", "Yellow")
  • moishy101
    New Member
    • Feb 2012
    • 46

    #2
    Sub Demo()
    Dim i As Integer
    Dim arrOne() As String, arrTwo() As String

    arrOne = Split("Apple,Or ange,Grape,Lemo n", ",")
    arrTwo = Split("Green,Or ange,Red,Yellow ", ",")

    'assuming that each source has the same number of names
    ReDim arrDestination( 0 To 1, 0 To UBound(arrOne))

    For i = 0 To UBound(arrDesti nation, 2)
    arrDestination( 0, i) = arrOne(i)
    arrDestination( 1, i) = arrTwo(i)
    Debug.Print arrDestination( 0, i), arrDestination( 1, i)
    Next
    End Sub

    Comment

    Working...