VBA remove duplicates from array code example
Example 1: vba code to remove duplicates from a column
Sub removeDuplicate()
Columns("A:A").Select
ActiveSheet.Range("$A$1:$A$117").RemoveDuplicates Columns:=Array(1), _
Header:=xlNo
Range("A1").Select
End Sub
Example 2: vba code to remove duplicates from a column
Sub dedupe_abcd()
Dim icol As Long
With Sheets("Sheet1")
icol = Application.Match("abcd", .Rows(1), 0)
With .Cells(1, 1).CurrentRegion
.RemoveDuplicates Columns:=icol, Header:=xlYes
End With
End With
End Sub
Example 3: add items to collection without duplicates VBA
Sub Sample()
Dim col As New Collection
On Error Resume Next
col.Add 111, Cstr(111)
col.Add 222, Cstr(222)
col.Add 111, Cstr(111)
col.Add 111, Cstr(111)
col.Add 333, Cstr(333)
col.Add 111, Cstr(111)
col.Add 444, Cstr(444)
col.Add 555, Cstr(555)
On Error GoTo 0
End Sub