Locate Values that are shown 3 or more times

bad Santa

New Member
Joined
Aug 16, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Looking for help identifying items that appear 3 or more times. I found this online and have spent two days trying to adjust it. How would I change this VBA to identify only items that appear 3 or more times instead of tow times.

Please help and thank you




Sub sbFindDuplicatesInColumn()
Dim lastRow As Long
Dim matchFoundIndex As Long
Dim iCntr As Long
Dim Occurances As Long

lastRow = Range("A65000").End(xlUp).Row

For iCntr = 1 To lastRow
If Cells(iCntr, 1) <> "" Then
matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" & lastRow), 0)
If iCntr <> matchFoundIndex Then
Cells(iCntr, 2) = "Duplicate"
End If
End If
Next
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Does this have to be a VBA solution? You can achieve this with conditional formatting

Book2
J
6A
7B
8A
9B
10C
11C
12A
13D
14E
15F
16F
17F
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J6:J17Expression=COUNTIF($J$6:$J$17,"="&J6)>=3textNO
 
Upvote 0
Or get a list:
Mr Excel Playground 3.xlsm
ABCD
1a3a
2b4b
3c1m
4d1
5e1
6f1
7b4
8g1
9h1
10b4
11j1
12k1
13a3
14l1
15m4
16n1
17a3
18b4
19m4
20m4
21m4
Sheet11
Cell Formulas
RangeFormula
D1:D3D1=INDEX(UNIQUE(FILTER(A1:B21,B1:B21>2)),,1)
B1:B21B1=SUM(--($A$1:$A$21=A1))
Dynamic array formulas.
 
Upvote 0
Nothing simpler than the data self analyzing in this case without having to go run a macro. Could also have a formula fill in the cells that you are filling in with your code.

Book2
JK
6ADuplicate
7B 
8ADuplicate
9B 
10C 
11C 
12ADuplicate
13D 
14E 
15FDuplicate
16FDuplicate
17FDuplicate
Sheet1
Cell Formulas
RangeFormula
K6:K17K6=IF(COUNTIF($J$6:$J$17,"="&J6)>2,"Duplicate","")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J6:J17Expression=COUNTIF($J$6:$J$17,"="&J6)>=3textNO
 
Upvote 0
Seriously, Conditional Formatting is easiest. Do you have some other process, possibly manual, that requires looking for the "Duplicate" values? If so, we can probably find a way to incorporate that. But if you really just want an updated macro, try this:

Rich (BB code):
Sub sbFindDuplicatesInColumn()
Dim myData As Variant, i As Long, lr As Long, myDict As Object, TopCell As Range, Out As Range

    Set TopCell = Range("A1")
    
    lr = Cells(Rows.Count, TopCell.Column).End(xlUp).Row
    myData = TopCell.Resize(lr).Value
    Set myDict = CreateObject("Scripting.Dictionary")
    For i = 1 To UBound(myData)
        myDict(myData(i, 1)) = myDict(myData(i, 1)) + 1
        If myDict(myData(i, 1)) >= 3 Then
            If Out Is Nothing Then
                Set Out = TopCell.Offset(i - 1, 2)
            Else
                Set Out = Union(Out, TopCell.Offset(i - 1, 2))
            End If
        End If
    Next i
    If Not Out Is Nothing Then Out.Value = "Duplicate"
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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