View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected][_2_] rumkus@hotmail.com[_2_] is offline
external usenet poster
 
Posts: 60
Default Easy way to merge 5-6 columns


Below sub will find unique values from the lists that are resided in
columns A,B,C and dump found values in column D.
Please check original post (By RB Smissaert) at:

http://groups.google.com/group/micro...b4b92724f904f3

Rgds


Sub GetUniqueItems()

Dim i As Long
Dim LR As Long
Dim arr
Dim arrUnique
Dim coll As Collection

Set coll = New Collection

'Column1

With Sheets(1)
LR = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range(.Cells(1), .Cells(LR, 1))
On Error Resume Next
For i = 1 To UBound(arr)
coll.Add arr(i, 1), CStr(arr(i, 1))
Next i
On Error GoTo 0
End With


'Column2

With Sheets(1)
LR = .Cells(.Rows.Count, 2).End(xlUp).Row
arr = .Range(.Cells(2), .Cells(LR, 2))
On Error Resume Next
For i = 1 To UBound(arr)
coll.Add arr(i, 1), CStr(arr(i, 1))
Next i
On Error GoTo 0
End With

'Column3

With Sheets(1)
LR = .Cells(.Rows.Count, 3).End(xlUp).Row
arr = .Range(.Cells(3), .Cells(LR, 3))
On Error Resume Next
For i = 1 To UBound(arr)
coll.Add arr(i, 1), CStr(arr(i, 1))
Next i
On Error GoTo 0
End With


'transfer the collection to an array
ReDim arrUnique(1 To coll.Count, 1 To 1)


For i = 1 To coll.Count
arrUnique(i, 1) = coll.Item(i)
Next i


'dump the array with unique numbers in Column4
With Sheets(1)
.Range(.Cells(4), .Cells(UBound(arrUnique), 4)) = arrUnique
End With

End Sub