VBA Dictionary trying to update code

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,174
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The code that I have below counts how many duplicates there are, in this case there are 4. I am looking to modify it to show me how many values make up the 4 duplicates the ans should be 13. Any help would be appreciated. Thanks in advance

<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC;
}
.tableizer-table th {
background-color: #104E8B;
color: #FFF;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>111</th></tr></thead><tbody>
<tr><td>111</td></tr>
<tr><td>111</td></tr>
<tr><td>222</td></tr>
<tr><td>222</td></tr>
<tr><td>222</td></tr>
<tr><td>333</td></tr>
<tr><td>444</td></tr>
<tr><td>555</td></tr>
<tr><td>555</td></tr>
<tr><td>777</td></tr>
<tr><td>777</td></tr>
<tr><td>777</td></tr>
<tr><td>777</td></tr>
<tr><td>777</td></tr>
</tbody></table>

Code:
Function HowManyMakeUpDupes(r As Range) As Long
Dim dic As New Dictionary
    For Each cell In r
        If Not dic.Exists(cell.Value) Then
            dic.Add cell.Value, 1
            Else
        dic.Item(cell.Value) = dic.Item(cell.Value) + 1
        End If
    Next
    For Each i In dic.Items
        If i > 1 Then
            HowManyMakeUpDupes = HowManyMakeUpDupes + 1
        End If
    Next
End Function
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe...

Code:
Function TotalDupes(r As Range) As Long
    Dim dic As Object, rCell As Range, v As Variant


    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    For Each rCell In r
        dic(rCell.Value) = dic(rCell.Value) + 1
    Next
    For Each v In dic.Items
        If v > 1 Then TotalDupes = TotalDupes + v
    Next v
End Function

M.
 
Upvote 0
Marcelo! Beautiful! Thank you very much! Does exactly what I want! Thanks again!
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top