I'm trying to modify this VBA Code I found at another site to be able to count duplicates with unique values that sometimes have delimiters. I messaged the site owner and haven't received a response so I am asking here for your help.
I have data in a column and sometimes the data has delimiters (always a forward slash). For example:
AA
CC
BB
AA/CC
AA/BB/CC
I would like to display the number of each unique value found. So in my example the result would be:
AA - 3
BB - 2
CC - 3
The code works great but it just doesn't work with delimiters. Thank you for your help.
I have data in a column and sometimes the data has delimiters (always a forward slash). For example:
AA
CC
BB
AA/CC
AA/BB/CC
I would like to display the number of each unique value found. So in my example the result would be:
AA - 3
BB - 2
CC - 3
VBA Code:
Sub Count_Duplicates_With_Unique_Values()
Set Rng = Range("B3:B13")
Count = 0
Count2 = 0
Output = ""
Match = False
Dim Elements() As Variant
ReDim Elements(0)
Elements(0) = "ExcelDemy"
For i = 1 To Rng.Rows.Count
For j = LBound(Elements) To UBound(Elements)
If Elements(j) = Rng.Cells(i, 1).Value Then
Match = True
Exit For
End If
Next j
If Match = False Then
Count2 = Count2 + 1
ReDim Preserve Elements(Count2)
Elements(Count2) = Rng.Cells(i, 1).Value
For j = 1 To Rng.Rows.Count
If Rng.Cells(j, 1) = Rng.Cells(i, 1) Then
Count = Count + 1
End If
Next j
Output = Output + vbNewLine + Rng.Cells(i, 1) + ": " + Str(Count)
Count = 0
End If
Match = False
Next i
MsgBox Output
End Sub
The code works great but it just doesn't work with delimiters. Thank you for your help.