Darthzo,
See the BOLD instructions (I hope they help).
Option Explicit
Sub GetUniqueListV2()
' stanleydgromjr, 04/03/2013
' http://www.excelforum.com/excel-programming-vba-macros/911706-how-to-understand-and-use-createobject-scripting-dictionary.html
Dim rng As Range, rng2 As Range, c As Range, v
With Sheets("A List")
'set the variable rng
' to sheet "A List", range A2:A20
Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
With Sheets("B List")
'set the variable rng2
' to sheet "B List", range A2:A14
Set rng2 = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
With CreateObject("Scripting.Dictionary")
'tell the Scripting.Dictionary to compare text
.CompareMode = vbTextCompare
'c is a range variable
' for each cell in the range A2:A20
For Each c In rng
'if c is not equal to a space
If c <> "" Then
'then check, if the value of c is not already a key in the dictionary object
If Not .Exists(c.Value) Then
'if it is Not in the dictionary object, then add value of c to a key
.Add c.Value, c.Value
End If
End If
Next
'the same instructions above relate to rng2 cells
For Each c In rng2
If c <> "" Then
If Not .Exists(c.Value) Then
.Add c.Value, c.Value
End If
End If
Next
'Transpose(Array(.Keys)) to variable array v
v = Application.Transpose(Array(.Keys))
End With
With Sheets("Unique List of items")
'clear the used range in Sheets("Unique List of items")
.UsedRange.ClearContents
With .Range("A1")
'write the title to cell A1
.Value = "Trust List"
'format cell A1, Bold, and underline the characters
.Font.Bold = True
.Font.Underline = xlUnderlineStyleSingle
End With
'write the contents of v to A2:A25
.Range("A2").Resize(UBound(v)) = v
'sort A2:A25 ascending
.Range("A2:A" & UBound(v) + 1).Sort key1:=.Range("A2"), order1:=1
'autofit the columns width
.Columns.AutoFit
'activate/select Sheets("Unique List of items")
.Activate
End With
End Sub
Bookmarks