计算列中有多少值具有重复项

时间:2013-03-12 18:39:17

标签: excel vba

我在列中有值:

08FHI800
08FHI800
08FHI800
07FJM933
07FJM933
89MNA900

我需要一个公式,告诉我列中有多少项具有相应的重复项。在这种情况下,它将是2.

2 个答案:

答案 0 :(得分:2)

尝试此公式,假设数据为A2:A100

=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")-(COUNTIF(A2:A100,A2:A100&"")=1))

它将忽略空白

答案 1 :(得分:0)

=SUMPRODUCT((A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")-(COUNTIF(A1:A12,A1:A12&"")=1))

以这些数据为例

Row#  ColA

1      1

2      2

3      2

4      2

5      3

6      4

7      5

8      5

9      6

10     6

11     6

12     7

将功能分为3个部分:

(A1:A12<>””)

COUNTIF(A1:A12,A1:A12&””)

COUNTIF(A1:A12,A1:A12&””)=1

组件1

(A1:A12<>””) evaluates to an array containing {T, T, T, T, T, T, T, T, T, T, T, T} ---------(1)

组件2

COUNTIF(A1:A12,A1:A12&””) 

评估为

COUNTIF({1,2,2,2,3,4,5,5,6,6,6,7},{1,2,2,2,3,4,5,5,6,6,6,7} 

,它计算每个值出现在范围内的次数 反过来,求值结果为:

{1,3,3,3,1,1,2,2,3,3,3,1}    -----------------(2)

(“&”是为了避免#DIV / 0错误)

现在,由于括号的原因,我们需要在查看组件3之前先评估(组件1 /组件2)。

组件1 /组件2是

(A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")

从(1)和(2)开始,

{T,T,T,T,T,T,T,T,T,T,T,T}/{1,3,3,3,1,1,2,2,3,3,3,1}

计算结果为:

{1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1}

现在我们可以看看 组件3

COUNTIF(A1:A12,A1:A12&””)=1

我们已经有了第一篇:

COUNTIF(A1:A12,A1:A12&””)

来自(2),其计算结果为

{1,3,3,3,1,1,2,2,3,3,3,1}  

将此与= 1结合起来

COUNTIF(A1:A12,A1:A12&””)=1

反过来求值为

{T,F,F,F,T,T,F,F,F,F,F,T}

所以,最终将所有这些结合在一起,我们有了

SUMPRODUCT({1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1} - {T,F,F,F,T,T,F,F,F,F,F,T})

现在,T等于1,F等于0,所以现在变成:

SUMPRODUCT({1-1,0.333-0, 0.333-0, 0.333-0,1-1,1-1,0.5-0,0.5-0, 0.333-0, 0.333-0, 0.333-0,1-1}

成为

SUMPRODUCT({0,0.333,0.333,0.333,0,0,0.5,0.5,0.333,0.333,0.333,0}

因为只有一个数组,所以SUMPRODUCT只是对元素求和

1+1+1 =3

有3个重复的项目。