View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default List unique values from multiple sheets

If speed is important then go for a routine like this:

Sub GetUniqueItems()

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

Set coll = New Collection

'pick up the numbers from sheet 1 and add to the collection
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

'pick up the numbers from sheet 2 and add to the collection
With Sheets(2)
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 sheet 3
With Sheets(3)
.Range(.Cells(1), .Cells(UBound(arrUnique), 1)) = arrUnique
End With

End Sub


If this is not fast enough then you could use the cCollection class in
dhRichClient3.dll, which can be downloaded he
www.datenhaus.de/Downloads/dhRichClient3.zip


RBS



"Steve" wrote in message
...
Hi all. I have a workbook with 3 sheets. In Column C in Sheet1 and
Sheet2, there is a huge list of account numbers, many of which are
duplicates. Conceptually, I am trying to look at Sheet1 Column C and
Sheet2 Column C, merge the two lists together into one large list, and
then write out all the UNIQUE values from the combined list on Sheet3
Column A. Possible? Thanks in advance for your help!