使用条件格式突出显示彼此不相邻的重复项(更大的数据集)

Highlight duplicates not next to each other using conditional formatting (Larger Dataset)

We have a list of product numbers in Excel in a certain order. For reasons I won't get into, we need to highlight when there are duplicates that aren't next to each other.Currently, I'm using this formula in a conditional format to do the job.

=AND(COUNTIF($A:$A,$A2)>1,$A1<>$A2,$A2<>$A3)

This mostly works well except in cases where there are pairs of duplicates like in the example below, we would want FO-1694 to be highlighted, because they aren't all next to each other. But we would not want NIS0257 to be highlighted because they are.

Currently

Ideally, this is what we want to see...

Expected

我最初在 1 月 30 日问过同样的问题() and I received what seemed to be a working 使用条件格式公式

=NOT(AND(A2=OFFSET(A2,COUNTIF($A2:$A,A2)-1,0),A2=OFFSET(A2,-(COUNTIF($A:$A2,A2)-1),0)))

虽然这个原始答案似乎适用于一小部分数据 (example),但它在更大的数据集(如我将要处理的数据集)上无法按需运行(下图是更大数据集的问题)。我根据需要调整了公式以适应更大的范围,因此您在更大的数据集图片和文件中看到的条件格式公式是

=NOT(AND(A2=OFFSET(A2,COUNTIF($A2:$A22,A2)-1,0),A2=OFFSET(A2,-(COUNTIF($A:$A2,A2)-1),0)))

箭头指向的单元格应突出显示

对于最后一张图片,即使它是范围的末尾,单元格仍应突出显示,因为它们是空白的,我也需要突出显示范围内的所有空白单元格。

可以使用此 link.

从我的保管箱帐户下载具有更大数据集的完整文件

我早该想到那些问题:

=NOT(AND(IFERROR(COUNTIF(OFFSET(A1,0,0,-COUNTIF($A:$A1,A2)),A2),0)=IFERROR(COUNTIF($A:$A1,A2),0),IFERROR(COUNTIF(OFFSET(A3,0,0,COUNTIF($A3:$A22,A2)),A2),0)=IFERROR(COUNTIF($A3:$A22,A2),0),A2<>""))

应该做。

我不确定这是否适合你

=IF(COUNTIF($A:$A,A2)>2,1,IF(AND(COUNTIF($A:$A,A2)=2,A1<>A2,A3<>A2),1,0))

我已经在一些测试数据上对其进行了测试,似乎可以正常工作。您需要检查第一行,因为您无法检查前一个单元格,所以 A1<>A2 部分..

1 在我的测试中是真实条件,因此需要调整条件格式。 享受。