salt_wagonner
New Member
- Joined
- Mar 10, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- MacOS
I have a data set with many duplicate values. I need to find duplicates from among a list of duplicates only if they appear inconsecutively. I know I'm not explaining this very well, so this picture might help:
In this example, "Apple" would be the only duplicate value I would want to list, because it appears in two separate groups. I don't care about the duplicate values that are consecutive to each other (rows 1-3, and 11-12), I care that the same value appears inconsecutively (row 2, row 11).
I have some code that I found on this site that works to identify and list the duplicate values, but it doesn't work for the functionality as I described it above. I'm not sure how to go about changing it, so if anyone has suggestions I would greatly appreciate it!
In this example, "Apple" would be the only duplicate value I would want to list, because it appears in two separate groups. I don't care about the duplicate values that are consecutive to each other (rows 1-3, and 11-12), I care that the same value appears inconsecutively (row 2, row 11).
I have some code that I found on this site that works to identify and list the duplicate values, but it doesn't work for the functionality as I described it above. I'm not sure how to go about changing it, so if anyone has suggestions I would greatly appreciate it!
VBA Code:
Sub TestForDuplicates()
Set r = Range("C2", Range("C" & Rows.Count).End(xlUp))
For Each c In r
If WorksheetFunction.CountIf(r, c) > 1 Then If InStr(1, s, c) = 0 Then s = s & vbCr & c
Next
MsgBox IIf(s <> "", "Found dup" & vbLf & Mid(s, 2), "No dup")
End Sub