Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 233
- Office Version
- 2016
- Platform
- Windows
Hi guys,
Any help here is much appreciate it. I am trying to exctract the unique records from the range below using data dictionary but my code is not working, not sure what I am missing.
Range:
Any help here is much appreciate it. I am trying to exctract the unique records from the range below using data dictionary but my code is not working, not sure what I am missing.
Range:
Brand | Color | Shape |
Toto | Blue | Round |
Toto | Blue | Round |
Toto | Blue | Square |
Toto | Blue | Triangular |
Glara | Green | Square |
Glara | Green | Square |
Glara | Black | Square |
Glara | White | Square |
VBA Code:
Sub GetUnique()
Dim Dict As Object
Dim i As Long, j As Long
Dim DRange() As Variant
Dim LastRow, LastCol As Long, NumRows As Long, NumCols As Long
LastRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.count, 1).End(xlUp).Row
Set DRange = Range("A1:D" & LastRow)
Set Dict = CreateObject("Scripting.Dictionary")
'Convert range to array and count rows and columns
NumRows = UBound(DRange)
NumCols = UBound(DRange, 2)
'put unique data elements in a dictionay
Set Dict = CreateObject("Scripting.Dictionary")
For i = 1 To NumCols
For j = 1 To NumRows
Dict(DRange(j, i)) = 1
Next j
Next i
Range("F2").Resize(Dict.count) = Application.Transpose(Dict.keys)
End Sub