Magic_Doctor
XLDnaute Barbatruc
VB:
Function MergeArrays(arr1() As Variant, arr2() As Variant) As Variant
'*********************************************
'Fusionne 2 matrices de longueurs différentes
'*********************************************
'- arr1 : 1ère matrice
'- arr2 : 2ème matrice
'https://stackoverflow.com/questions/1588913/how-do-i-merge-two-arrays-in-vba
Dim returnThis() As Variant, len1 As Integer, len2 As Integer, lenRe As Integer, counter As Integer
len1 = UBound(arr1)
len2 = UBound(arr2)
lenRe = len1 + len2
ReDim returnThis(1 To lenRe)
counter = 1
Do While counter <= len1 'get first array in returnThis
returnThis(counter) = arr1(counter)
counter = counter + 1
Loop
Do While counter <= lenRe 'get the second array in returnThis
returnThis(counter) = arr2(counter - len1)
counter = counter + 1
Loop
MergeArrays = returnThis
End Function
Dernière édition: