View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Prof Wonmug Prof Wonmug is offline
external usenet poster
 
Posts: 61
Default Easy way to merge 5-6 columns

On Tue, 24 Aug 2010 15:56:07 -0700 (PDT), "
wrote:


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


Thanks for that. I have it copied into one of my add-in modules, but
can't figure out how to run it. Up to now, I've only used functions
(UDFs) that I call from inside a cell expression (=myudf(A1)).

I tried that (=GetUniqueItems()) and got the "#NAME?" error.

I am able to run UDFs in this manner from that same add-in module.

How to I get this SUB to execute?

I tried Alt-F8, but no macros were visible.