Question : How to concatenate two one dimensional arrays

Hi.

I have two separate arrays with numbers and blanks "" and I need to concatenate them using VBA.
Example:

I need ResultArray in the Code sample below to be ("",2,"",25,34,"","",17)

How can I do this.

Appreciate your help.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Sub Concat()
 
    Dim ResultArray() As Variant
    Dim ArrayToAppend() As Variant
                    
    ReDim ResultArray(4)
    ReDim ArrayToAppend(4)
    
    ResultArray(0) = ""
    ResultArray(1) = 2
    ResultArray(2) = ""
    ResultArray(3) = 25
    
    ArrayToAppend(0) = 34
    ArrayToAppend(1) = ""
    ArrayToAppend(2) = ""
    ArrayToAppend(3) = 17
 
' Code for concatenation
 
end sub

Answer : How to concatenate two one dimensional arrays

Try this:


AW


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Dim resultingArray() As Variant
ReDim resultingArray(UBound(ResultArray) + UBound(ArrayToAppend))
 
Dim iArray As Integer
Dim jArray As Integer
 
For iArray = LBound(ResultArray) To UBound(ResultArray) - 1
   jArray = iArray
   resultingArray(jArray) = ResultArray(iArray)
Next iArray
 
For iArray = LBound(ArrayToAppend) To UBound(ArrayToAppend) - 1
   jArray = jArray + 1
   resultingArray(jArray) = ArrayToAppend(iArray)
Next iArray
Random Solutions  
 
programming4us programming4us