Hi jaffermo
This code is in the attached and appears to do as you require.
Please note that the code requires you to set a reference to Microsoft Scripting Runtime... Tools > Reference > Microsoft Scripting Runtime
You'll need to think about how to implement...I don't know your process. The code can be adapted to whatever that process is. Let me know of issues.
Option Explicit
Sub FindTotals()
Dim a As Variant
Dim LR As Long
Dim i As Long
LR = Range("G" & Rows.Count).End(xlUp).Row
a = Worksheets("Feuil1").Range("G2:G" & LR).Value
a = UniqueArray(a)
Range("E" & LR + 3).Resize(1, UBound(a) + 1) = a
For i = 0 To UBound(a)
Range("E" & LR + 3).Offset(1, i).Formula = "=countif(G2:G" & LR & "," & Range("E" & LR + 3).Offset(0, i) & ")"
Next i
Range("D" & LR + 3).Value = "portfolio:"
Range("D" & LR + 3).HorizontalAlignment = xlRight
Range("D" & LR + 4).Value = "# of times repeated:"
Range("D" & LR + 4).HorizontalAlignment = xlRight
End Sub
Function UniqueArray(anArray As Variant) As Variant
'Requires, Tools > Reference > Microsoft Scripting Runtime, scrrun.dll
Dim d As New Scripting.Dictionary, a As Variant
With d
.CompareMode = TextCompare
For Each a In anArray
If Not Len(a) = 0 And Not .Exists(a) Then
.Add a, Nothing
End If
Next a
UniqueArray = d.keys
End With
Set d = Nothing
End Function
Bookmarks