Hello, I am trying to combine two ranges into one array to be used in functions that can only take a continuous array as an input. I am close to successfully creating the function to do that, but it looks like I am doing something wrong. The function works fine if the two ranges I am trying to combine have more than one value, but breaks down if one of the arrays has only one value, except if the one value is a number. For example if the two ranges comprise of dates and the second range only has one date, the function does not work. But if it is one number, then it works. Any help would be appreciated. Code posted below:
[pre]
[/pre]
[pre]
Code:
Function mergeArrays2(Array1, Array2)
Dim holdarr As Variant
Dim ub1 As Long, arr1 As Variant, arr2 As Variant
Dim ub2 As Long
Dim bi As Long
Dim i As Long
Dim newind As Integer
arr1 = Application.Index(Array1.Value, 0)
arr2 = Application.Index(Array2.Value, 0)
newind = 0
ub1 = UBound(arr1)
ub2 = UBound(arr2)
bi = ub1 + ub2
ReDim holdarr(ub1 + ub2 - 1)
For i = 1 To bi
If i <= ub1 Then
holdarr(newind) = arr1(i)
newind = newind + 1
End If
If i > ub1 And i <= bi Then
For j = 1 To ub2
holdarr(newind) = arr2(j)
newind = newind + 1
i = i + 1
Next j
End If
Next i
mergeArrays2 = holdarr
End Function