Hello Tee51,
This should work correctly.
Sub CommandButton1_Click()
Dim Data As Variant
Dim Dict As Object
Dim Key As String
Dim MyList() As Variant
Dim n As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Worksheets("Sheet1").Range("A2")
Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Rng.Parent.Range(Rng, RngEnd)
Rng.ClearContents
Data = Rng.Resize(ColumnSize:=2).Value
Set Dict = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Data, 1)
Key = Trim(Data(i, 1))
If Key <> "" Then
If Not Dict.Exists(Key) Then
Dict.Add Key, Data(i, 2)
End If
If Dict(Key) <> Data(i, 2) Then
ReDim Preserve MyList(n)
MyList(n) = Key
n = n + 1
End If
End If
Next i
If Dict.Count > 0 Then
Wks.Range("A2").Resize(UBound(MyList, 1) + 1).Value = Application.Transpose(MyList)
End If
End Sub
Bookmarks