As for the function explanation, here is the function code commented:
'InStringArray boolean function returns true if sValue is in vArray
Function InStringArray(ByRef vArray() As String, ByVal sValue As String) As Boolean
' Dimension variable to be used as array index
Dim i As Long
' Loop index variable for each item of array, from lower bound to upper bound
For i = LBound(vArray) To UBound(vArray)
' If that array item's value is sValue, then item is in array, and function
' can be exited with function value being True
If vArray(i) = sValue Then InStringArray = True: Exit Function
' loop to next item's index
Next i
' This is only processed if sValue wasn't found in array, makes function return
' a false value
InStringArray = False
End Function
And here is the Sub
Sub MergeLists()
Dim TheList() As String, i As Long, j As Long, ListCount As Long
' Initialize array counting variable
ListCount = 0
' Redimensions array variable so it can be passed to InStringArray function
' (otherwise there will be no bounds to the array and the function errors)
ReDim TheList(ListCount)
' Add unique names from column A and B to array
' Returns the last used row number in column A to variable j
j = Range("A65536").End(xlUp).Row
' if j is greater than 4, then there is data in the sheet (as rows 5 and above
' are the data rows, based on your description)
If j > 4 Then
' 'i' variable is used to loop through the used cells in column A
For i = 5 To j
' If the cell in column A is not already in TheList array variable...
If Not InStringArray(TheList, Range("A" & i).Text) Then
' This is dynamically increasing the size of the array
ReDim Preserve TheList(ListCount)
' Puts that cell's contents into end of array
TheList(ListCount) = Range("A" & i).Text
' Increases array counting variable
ListCount = ListCount + 1
End If 'If Not InStringArray ....
' go to next cell
Next i
End If 'If j > 4 ...
' Same logic as above, but using column B instead of A
j = Range("B65536").End(xlUp).Row
If j > 4 Then
For i = 5 To j
If Not InStringArray(TheList, Range("B" & i).Text) Then
ReDim Preserve TheList(ListCount)
TheList(ListCount) = Range("B" & i).Text
ListCount = ListCount + 1
End If
Next i
End If
' Transfer array contents to column D
' I have listcount - 1 as listcount is increased whenever anything is added to
' the array variable for easier re-dimensioning
For i = 0 To ListCount - 1
' Enter array entry into column D
Range("D5").Offset(i, 0) = TheList(i)
' Next entry
Next i
End Sub
Hopefully those are commented enough, but as arrays can get tricky please feel free to ask about what you don't understand!
Matt