It is very easy and practical using the dictionary. The logic is similar to Kittoes answer, but the object dictionary is much faster, more efficient, and you can output an array of all the keys and elements that you want to do here. I have simplified the code to create a list from column A, but you will get this idea.
Sub UniqueReport() Dim dict As Object Set dict = CreateObject("scripting.dictionary") Dim varray As Variant, element As Variant varray = Range("A1:A10").Value 'Generate unique list and count For Each element In varray If dict.exists(element) Then dict.Item(element) = dict.Item(element) + 1 Else dict.Add element, 1 End If Next 'Paste report somewhere Sheet2.Range("A1").Resize(dict.Count, 1).Value = _ WorksheetFunction.Transpose(dict.keys) Sheet2.Range("B1").Resize(dict.Count, 1).Value = _ WorksheetFunction.Transpose(dict.items) End Sub
How it works : you just give the range to an array of options to scroll quickly, and then add them to the dictionary. If it exists, you simply take the element that goes with it (starts at 1) and adds it to it. Then at the end just delete the unique list and the counts where you need it. Please note that the way to create an object for the dictionary allows you to use it - there is no need to add a link to your code.
source share