How to identify duplicate values only if they appear inconsecutively?

salt_wagonner

New Member
Joined
Mar 10, 2023
Messages
6
Office Version
  1. 365
Platform
  1. 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:

Screen Shot 2023-03-10 at 8.18.17 AM.png


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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
A no-code version

MrExcelPlayground16.xlsx
ABCD
10AppleTRUEApple
11AppleTRUEPotato
12AppleTRUE
13BananaFALSE
14BananaFALSE
15AppleTRUE
16AppleTRUE
17PotatoTRUE
18PotatoTRUE
19SquashFALSE
20SquashFALSE
21SquashFALSE
22PotatoTRUE
Sheet10
Cell Formulas
RangeFormula
D10:D11D10=UNIQUE(FILTER(A10:A22,B10:B22))
B10:B22B10=LET(a,A10=$A$10:$A$22,b,a*SEQUENCE(ROWS(a)),c,FILTER(b,b>0),d,ROWS(c),e,INDEX(c,1)+d-1,f,INDEX(c,d),IF(f<>e,TRUE,FALSE))
Dynamic array formulas.
 
Upvote 0
Solution
A no-code version

MrExcelPlayground16.xlsx
ABCD
10AppleTRUEApple
11AppleTRUEPotato
12AppleTRUE
13BananaFALSE
14BananaFALSE
15AppleTRUE
16AppleTRUE
17PotatoTRUE
18PotatoTRUE
19SquashFALSE
20SquashFALSE
21SquashFALSE
22PotatoTRUE
Sheet10
Cell Formulas
RangeFormula
D10:D11D10=UNIQUE(FILTER(A10:A22,B10:B22))
B10:B22B10=LET(a,A10=$A$10:$A$22,b,a*SEQUENCE(ROWS(a)),c,FILTER(b,b>0),d,ROWS(c),e,INDEX(c,1)+d-1,f,INDEX(c,d),IF(f<>e,TRUE,FALSE))
Dynamic array formulas.
My date set has thousands of rows, so I need it to be a bit more automated, but thank you for commenting.
 
Upvote 0
A no-code version

MrExcelPlayground16.xlsx
ABCD
10AppleTRUEApple
11AppleTRUEPotato
12AppleTRUE
13BananaFALSE
14BananaFALSE
15AppleTRUE
16AppleTRUE
17PotatoTRUE
18PotatoTRUE
19SquashFALSE
20SquashFALSE
21SquashFALSE
22PotatoTRUE
Sheet10
[/XtR]
[XR]
Cell Formulas
RangeFormula
D10:D11D10=UNIQUE(FILTER(A10:A22,B10:B22))
B10:B22B10=LET(a,A10=$A$10:$A$22,b,a*SEQUENCE(ROWS(a)),c,FILTER(b,b>0),d,ROWS(c),e,INDEX(c,1)+d-1,f,INDEX(c,d),IF(f<>e,TRUE,FALSE))
Dynamic array formulas.
I've been playing around with your formula and I can get it to work with one word strings, but not with longer strings, which is what my data has. Can you tell me if the formula should be able to work for longer strings?
 
Upvote 0
What about this, without the helper column?

23 03 13.xlsm
ABC
1DataSplit
2AppleApple
3ApplePotato
4Apple
5Banana
6Banana
7Apple
8Apple
9Potato
10Potato
11Squash
12Squash
13Squash
14Potato
15
Split Data
Cell Formulas
RangeFormula
C2:C3C2=LET(r,A2:A14,u,UNIQUE(r),rw,ROW(r),FILTER(u,(XLOOKUP(u,r,rw,,,-1)-XLOOKUP(u,r,rw)+1)<>COUNTIF(r,u),""))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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