Option Explicit
Option Base 1
'This macro will create a third list by concatenating two lists
'---------------------------------------------------------------------------------------------------------------------
'Adapted: http://www.eggheadcafe.com/software/aspnet/33754898/how-to-combine-arrays.aspx (Joe)
' http://www.ozgrid.com/forum/showthread.php?t=92426 (Post # 4)
' http://www.excelforum.com/excel-programming/738644-type-mismatch-error-13-transpose-dynamic-name-range-when-range-refers-to-single-cell.html
'---------------------------------------------------------------------------------------------------------------------
Public Sub ConcatenateArray()
Dim vArray1 'List of companies in the data entry form
Dim vArray2 'List of companies in the database
Dim vArray3 'Concatenated list
Dim i As Integer
Dim iSizeA1 As Integer 'Number of elements in vArray1
Dim iSizeA2 As Integer 'Number of elements in vArray2
'Transpose the lists (single column range) to a one dimensional array
On Error Resume Next
With Names("Test").RefersToRange
vArray1 = WorksheetFunction.Transpose(.Parent.Evaluate("IF(ROW(" & .Address & ")," & .Address & ")"))
End With
MsgBox "Empty List. Nothing to update"
On Error Goto Errhandler
With Names("DB").RefersToRange
vArray2 = WorksheetFunction.Transpose(.Parent.Evaluate("IF(ROW(" & .Address & ")," & .Address & ")"))
End With
'Determine the number of elements in vArray1 & vArray2
iSizeA1 = UBound(vArray1)
iSizeA2 = UBound(vArray2)
'Set vArray3 = vArray2 & then add elements from vArray1 to this list
vArray3 = vArray2
ReDim Preserve vArray3(1 To iSizeA1 + iSizeA2)
For i = 1 To iSizeA1
vArray3(iSizeA2 + i) = vArray1(i)
Next i
Errhandler:
vArray3 = vArray1
End Sub
Bookmarks