Caleeco
Well-known Member
- Joined
- Jan 9, 2016
- Messages
- 980
- Office Version
- 2010
- Platform
- Windows
Hello,
I am attempting to remove duplicates from a set range. However, I need it to be only the range defined and not the entire column.
I read an example online whereby a unique list is created by adding each row of data to a collection (resume next on errors).
My code below correctly identifies the number of unique values in the data set stored in range A1:A7.
However, I cant work out how to then paste each item of the collection in cell D5 onwards (D6, D7, D8, etc)
Any help is much appreciated!
I am attempting to remove duplicates from a set range. However, I need it to be only the range defined and not the entire column.
I read an example online whereby a unique list is created by adding each row of data to a collection (resume next on errors).
My code below correctly identifies the number of unique values in the data set stored in range A1:A7.
However, I cant work out how to then paste each item of the collection in cell D5 onwards (D6, D7, D8, etc)
Any help is much appreciated!
Code:
Sub RemoveDuplicate()
Dim NoDuplicates As New Collection
Dim rData As Range
Dim Cell As Range
Dim lrow As Long
Dim Item As Object
Set rData = ActiveSheet.Range("A1", Range("A" & Rows.Count).End(xlUp))
On Error Resume Next
For Each Cell In rData
NoDuplicates.Add Cell.Value, CStr(Cell.Value)
Next
MsgBox "Number of Unique Values: " & NoDuplicates.Count
lrow = 5
For Each Item In NoDuplicates
ActiveSheet.Range("D" & lrow) = Item.Value
lrow = lrow + 1
Next Item
End Sub
Last edited: